: 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