SQL Transaction Usage

Source: Internet
Author: User

SQL Transaction Usage

Simply put, a transaction is a mechanism for maintaining the integrity of the database.

Its implementation form is to embed ordinary SQL statements into the BEGIN Tran ... Commit Tran (or full form Begin Transaction ... Commit Transaction), and, of course, you can use rollback Tran to roll back the transaction if necessary, that is, undo the operation.

Using the transaction mechanism, the operation of the database is all executed, or all is not executed, to ensure the consistency of the database. SQL statements that require the use of transactions are usually update and delete operations, and so on.

It is important to note that a transaction does not support nesting, that is, a form similar to this is not allowed:
Begin Tran
...
Begin Tran
...
Commit Tran
...
Commit Tran

Of course, the query does not have to use transactions because the query does not change the data and does not break the integrity.

The display transaction is marked with the BEGIN TRANSACTION and end transaction, where the update and DELETE statements are either executed or all are not performed. Such as:
BEGIN TRANSACTION T1
Update student
Set Name= ' Tank '
where id=2006010
Delete from student
where id=2006011
Commit
End Transaction T1

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.