Introduction to Transactions

A supposedly underrated topic for SQL enthusiasts, Transactions are a vital part of any SQL query.

Suppose that for whatever reason, the second update statement should update exactly five rows. If @@ROWCOUNT, which hold the number of rows affected by each statement, is five then the transaction commits otherwise it rolls back. The ROLLBACK TRAN statement “undoes” all the work since the matching BEGIN TRAN statement. It will not perform either update statement. Note that Query Analyzer will show you messages indicating that rows were updated but you can query the database to verify that no actual data modifications took place.

Source: http://www.sqlteam.com/article/introduction-to-transactions

Leave a comment