Explicit User-Defined Transactions

To have complete control of a transaction and define logical units of work that consist of multiple data modifications, you need to write explicit user-defined transactions. Any SQL Server user can make use of the transaction control statements; no special privileges are required.

To start a multistatement transaction, use the BEGIN TRAN command, which optionally takes a transaction name:

BEGIN TRAN[SACTION] [transaction_name [WITH MARK ['description']]]

The transaction name is essentially meaningless as far as transaction management is concerned, and if transactions are nested (which is discussed later in this chapter), the name is useful only for the outermost BEGIN TRAN statement. Rolling back to any other ...

Get Microsoft® SQL Server 2008 R2 Unleashed 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.