Transaction Commands and Syntax

As I said earlier, the BEGIN TRAN, COMMIT TRAN, and ROLLBACK TRAN commands are used to manage transactions in Transact-SQL. (The sp_xxxx_xact system stored procedures are legacy code that was used in the past with DB-Library two-phase commit applications, and you should not use them.) The exact syntax used to begin a transaction is:

BEGIN TRAN[SACTION] [name|@TranNameVar]

To commit a transaction, use:

COMMIT TRAN[SACTION] [name|@TranNameVar]

And to roll back a transaction, use:

ROLLBACK TRAN[SACTION] [name|@TranNameVar]

You can also use the COMMIT WORK and ROLLBACK WORK commands in lieu of COMMIT TRANSACTION and ROLLBACK TRANSACTION, though you cannot use transaction names with them.

Nested Transactions

Get Guru's Guide to SQL Server Architecture and Internals, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.