Things in SQL

Source: Internet
Author: User
Tags rollback

: a transaction (Transaction) is a unit of concurrency control and is a user-defined sequence of operations. These operations are either done or not, and are an inseparable unit of work. With transactions, SQL Server can bind a logically related set of operations so that the server maintains the integrity of the data.
(2): A transaction usually begins with a BEGIN transaction and ends with a commit or rollback.
Commit represents the commit, which commits all operations of the transaction. Specifically, all updates to the database in a transaction are written back to the physical database on disk, and the transaction ends normally.
Rollback represents a rollback, in which a transaction fails to proceed while the transaction is running, and the system undoes all of the completed operations on the database in the transaction and rolls back to the state where the transaction started.
(3): Three modes of transaction operation:
A: Auto COMMIT Transaction
Each individual statement is a transaction. A commit is implied after each statement.
B: an explicit transaction
Begin explicitly with BEGIN TRANSACTION, ending explicitly with commit or rollback.
C: Implicit transactions
When the previous transaction completes, the new transaction is started implicitly, but each transaction still ends explicitly with commit or rollback.
(4): Characteristics of the transaction (acid characteristics)
A: atomicity (atomicity)
A transaction is a logical unit of work for a database, and all operations included in the transaction are either done or not.
B: Consistency (consistency)
The result of the transaction execution must be to change the database from one consistent state to another. Consistency is closely related to atomicity.
C: Isolation (Isolation)
Execution of one transaction cannot be disturbed by other transactions.
D: Persistent/permanent (durability)
Once a transaction is committed, its changes to the data in the database should be permanent.
Note: Transactions are the basic unit of recovery and concurrency control.

To make an analogy:

If we want to modify a record in a table, you can use the following methods:
First delete the original record, and then insert the modified new record
There are 2 steps in this process
Data loss occurs if a record deletion succeeds, but the insertion is unsuccessful for some reason.
This time, you can use things to deal with
Delete and insert as one thing, must be 2 steps are successful, the data has changed.
Otherwise, if the deletion succeeds and the insert fails, you want to automatically rollback and revert to the original state.

Things in SQL

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.