Delete and paste inside a single SQL transaction

I just want to ask if the first request will always be executed when a transaction is encapsulated? For example, I received 500 k records for deletion and 500 k for insertion, is there a possibility of blocking? In fact, I have already tested this query and it works fine, but I want to make sure my assumption is correct.

Note: this will delete and insert the same record, possibly updating in other columns.

BEGIN TRAN;
    DELETE FROM OUTPUT TABLE WHERE ID = (1,2,3,4 etc)
    INSERT INTO OUTPUT TABLE Values (1,2,3,4 etc) 
COMMIT TRAN;
+4
source share
2 answers

( , ) . , (X), , . , , DELETE INSERT , , DELETE, INSERT.

, 500 . , . .

500 . 500 . , , , , - . , , . , , , SQL Server ( ).

(, 10000 ), MERGE DELETE/INSERT ( ) , , , , . .

+5

TRANSACTION ( ):

BEGIN TRANSACTION , , . , BEGIN TRANSACTION , . , COMMIT TRANSACTION, , ROLLBACK TRANSACTION.

BEGIN TRANSACTION . , , Transact-SQL , , COMMIT TRANSACTION, ROLLBACK TRANSACTION. , .

BEGIN TRANSACTION , , , , , INSERT, UPDATE DELETE. , SELECT, , .

+1

All Articles