I have the following transaction:
- SQL inserts a 1 new record into a table called tbl_document
- SQL deletes all records matching a criteria in another table called tbl_attachment
- SQL inserts multiple records into the tbl_attachment
Until this transaction finishes, I don’t want others users to be aware of the (1) new records in tbl_document, (2) deleted records in tbl_attachment, and (3) modified records in tbl_attachment.
Would Read Committed Isolation be the correct isolation level?
yes, like this:
you may block/lock users until you are finished and commit/rollback the transaction. Also, someone could SELECT your rows from tbl_attachment after your insert into tbl_document but before your delete. If you need to prevent that do this:
or just delete tbl_attachment before the insert into tbl_document and forget the select with the locking hints.