|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 11:12 AM
Points: 578,
Visits: 3,258
|
|
Hi everyone,
I wanted to know what is the transaction scope for the following batch. Does SQL Server commit the changes after every delete or does it commit after the last delete? And SET IMPLICIT_TRANSACTIONS is set to OFF. Thanks in advance.
DELETE FROM table1
DELETE FROM table2
DELETE FROM table3
DELETE FROM table4
DELETE FROM table5
DELETE FROM table6
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 9:55 PM
Points: 2,471,
Visits: 2,066
|
|
By default, each statement is a transaction of its own. So, each delete statement is committed before the next one starts.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 11:12 AM
Points: 578,
Visits: 3,258
|
|
Thanks! Made a mistake at work by thinking that the whole batch is a transaction. Yikes. Good thing I test my backups regularly.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Yesterday @ 3:18 PM
Points: 37,744,
Visits: 30,025
|
|
However this isn't that much better.
BEGIN TRANSACTION DELETE FROM table1
DELETE FROM table2
DELETE FROM table3
DELETE FROM table4
DELETE FROM table5
DELETE FROM table6 COMMIT TRANSACTION
What do you think will happen if the delete from table3 fails (foreign key violation)?
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|