Partial transaction rollback in SQL Server

Source: Internet
Author: User
Partial transaction rollback in SQL Server

1. Save point: a partial rollback method. You can name a storage point so that you can roll back to the storage point in subsequent transactions. 2. Implementation Code. Begin transaction transaction_name
SQL _statement1
SQL _statement2 save transaction save_name -- set the storage point SQL _statement3
SQL _statement4if test_condition_fails rollback transaction save_name -- roll back to the storage point SQL _statement5
SQL _statement6commit transaction transaction_name or begin transaction transaction_name
SQL _statement1
SQL _statement2
Save transaction save_name -- set the save point
SQL _statement3
SQL _statement4
If test_condition_fails)
Begin
Rollback transaction save_name -- roll back to the Save point
Return
End
Else
Begin
SQL _statement5
SQL _statement6
End
Commit transaction transaction_name 3. If no point is saved, the rollback command can only be followed by the name of the outermost transaction, rather than the name of other transactions. Regardless of the layer in which the rollback command is nested, if there is no transaction name afterwards, the transaction will be rolled back to the top layer, which is the same as rolling back the outermost layer of the transaction. In a nested transaction, you cannot roll back only a certain level of transactions, unless you specify a save point and then roll back to the Save point.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.