SQL Server review-transaction

Source: Internet
Author: User
Tags savepoint

Why use transactions?
When updating multiple tables, an execution fails. Transaction rollback is required to maintain data integrity.
 
Display Set transactions

   Begin  Try  Begin   Transaction      Insert   Into Shiwu (ASD) Values ( '  Aasdasda  '  );  Commit   Transaction    End  Try Begin  Catch  Select Error_number () As  Errornumber  Rollback   Transaction    End Catch

 
Implicitly set transactions

 Set Implicit_transactions On ; --  Start implicit transactions    Go      Begin Try  Insert   Into Shiwu (ASD) Values ( '  Aasdasda  '  );  Insert   Into Shiwu (ASD) Values ( '  Aasdasda  '  );  Commit  Transaction  ;  End  Try  Begin  Catch  Select Error_number () As  Errornumber  Rollback   Transaction ; --  Roll back a transaction    End  Catch  Set Implicit_transactions Off ; --  Disable implicit transactions    Go 

Show that the following statements of the transaction are not available, and the implicit transaction can

Alter database;
Backup;
Create database;
Drop database;
Reconfigure;
Restore;
Update statistics;

Show that transactions can be nested

 --  Create a stored procedure    Create   Procedure  Qiantaoproc  @ ASD   Nchar (10  )  As    Begin      Begin  Try  Begin   Transaction  Innertrans  Save   Transaction Savepoint --  Create a transaction retention point          Insert   Into Shiwu (ASD)Values ( @ ASD  );  Commit   Transaction  Innertrans  End  Try  Begin  Catch  Rollback   Transaction Savepoint --  Roll back to the Save point          Commit   Transaction Innertrans  End  Catch  End    Go      Begin   Transaction  Outrans  Exec Qiantaoproc '  Asdasd  '  ;  Rollback   Transaction Outrans

transaction nesting. When an outer transaction is rolled back, an exception occurs if the nested transaction has been rolled back. In this case, you need to use the transaction storage point. Code .

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.