Proper way to use a transaction around multiple inserts or updates
问题 What is the proper way to test for insert/update failures and rollback this transaction if there are any? I don't think what I have will work since my inserts/updates are 3 separate statements and the @@ROWCOUNT will only reflect the last statement executed. BEGIN TRANSACTION Script; GO INSERT INTO TableA (id) VALUES (1) INSERT INTO TableB (id) VALUES (1) UPDATE TableC SET id=1 WHERE id=2 GO IF (@@ROWCOUNT=3 AND @@ERROR=0) BEGIN COMMIT END ELSE BEGIN PRINT 'Error: Rolling back transaction'