Using Transactions : TRANSACTION « Transaction « SQL Server / T-SQL Tutorial






To begin a transaction, issue the BEGIN TRANSACTION (or BEGIN TRAN) statement.

This tells SQL Server that all the following changes to the database occur as a unit of work.

Syntax for BEGIN TRANSACTION

BEGIN TRAN [ SACTION ] [ transaction_name | @tran_name_variable
[ WITH MARK [ 'description' ] ] ]
If you decide that all is well, you can issue the COMMIT TRAN or COMMIT WORK statement.  Syntax for COMMIT TRAN and COMMIT WORK
COMMIT [ TRAN [ SACTION ] [ transaction_name | @tran_name_variable ] ]
COMMIT [ WORK ]

If you need to undo all of your work, you can issue a ROLLBACK TRAN or ROLLBACK WORK statement.

Syntax for ROLLBACK TRAN and ROLLBACK WORK

ROLLBACK [ TRAN [ SACTION ]
 [ transaction_name | @tran_name_variable
 | savepoint_name | @savepoint_variable ] ]
ROLLBACK [ WORK ]








23.1.TRANSACTION
23.1.1.A transaction is bound by the ACID test. ACID stands for Atomicity, Consistency, Isolation (or Independence), and Durability:
23.1.2.Explicit Transaction Commands
23.1.3.Using Transactions
23.1.4.BEGIN TRANSACTION
23.1.5.Using Explicit Transactions
23.1.6.Forcing an exclusive table lock.
23.1.7.Transaction spread across batches:
23.1.8.Exception before transaction committing
23.1.9.statements coded as a transaction
23.1.10.A script with nested transactions
23.1.11.One batch that contains two transactions
23.1.12.What happens with stored proc transactions and exceptions?
23.1.13.Declare variable in a transaction
23.1.14.Inserting a Row into MyTable and Rolling Back the Transaction