This is the SQL Server's document talking about the ROLLBACK statement. On that page it states that the syntax of it is as follows:

     [ transaction_name | @tran_name_variable  
     | savepoint_name | @savepoint_variable ]   
[ ; ]  

Apparently the stuff inside square brackets are optional and it seems you should choose one from TRAN or TRASACTION. But in fact you can completely omit both and ROLLBACK is a perfectly valid statement. Is this an error or intentionally?


The ROLLBACK TRANSACTION documentation is correct, albeit not clear without additional context.

ROLLBACK is shorthand for the similar ROLLBACK WORK statement rather than ROLLBACK TRANSACTION. Below is an excerpt from the ROLLBACK WORK doc page:


This statement functions identically to ROLLBACK TRANSACTION except that ROLLBACK TRANSACTION accepts a user-defined transaction name. With or without specifying the optional WORK keyword, this ROLLBACK syntax is ISO-compatible.

When nesting transactions, ROLLBACK WORK always rolls back to the outermost BEGIN TRANSACTION statement and decrements the @@TRANCOUNT system function to 0.

Note the same applies to the similar COMMIT TRANSACTION and COMMIT WORK statements.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.