SQL Server: How Transactions Work

In SQL Server, the number of transactions will be performed?

DECLARE @deleted BIGINT
SET @deleted = 100000
WHILE @deleted = 100000
BEGIN
DELETE TOP(100000) FROM MYTABLE WITH (ROWLOCK)
where Col1 = 7048 and COL2 = 39727 and Col3 = 0
SET @deleted = (SELECT @@ROWCOUNT)
END

If I canceled it after starting within 10 minutes, do you need to back off?

Would add a transaction and a transaction with a transaction if I do not want it to roll back after one iteration after cancellation?

It doesn't matter if I put it in a stored procedure?

+3
source share
3 answers

If you do not BEGIN TRANSACTIONand COMMIT, you mean transactions. And each DELETEwill be a separate transaction. So, if you cancel the script, it will roll back the current command. But all the previous steps DELETEhave already been completed.

BEGIN TRANSACTION COMMIT , . , , . ROLLBACK, .

+4

. ACID? SQL Server - , , ACID

+2

, ( SQL Server ). Profiler . . Begin Tran ( End Tran) . , .

-2

Source: https://habr.com/ru/post/1768104/


All Articles