Traditional Culture Encyclopedia - Traditional customs - How do you understand things in a database that feel abstract?

How do you understand things in a database that feel abstract?

(1):A transaction (Transaction) is a unit of concurrency control, a user-defined sequence of operations. These operations either all do or none do, and are an indivisible unit of work. Through transactions, SQL Server is able to bind a logically related set of operations together so that the server maintains the integrity of the data.

(2):Transactions usually start with BEGIN TRANSACTION and end with COMMIT or ROLLBACK.

COMMIT means commit, that is, commit all operations of the transaction. Specifically, all updates to the database in the transaction are written back to the physical database on disk, and the transaction ends normally.

ROLLBACK means rollback, that is, in the process of running a transaction in the occurrence of some kind of failure, the transaction can not continue, the system will be in the transaction to complete all the operations on the database to undo all the roll back to the beginning of the transaction state.

(3):Three modes of transaction operation:

A:Auto-commit transaction

Each individual statement is a transaction. A COMMIT is implied after each statement.

B:Explicit Transactions

Start explicitly with BEGIN TRANSACTION and end explicitly with COMMIT or ROLLBACK.

C:Implicit Transaction

A new transaction is implicitly started when the previous one completes, but each transaction still ends explicitly with a COMMIT or ROLLBACK.

(4):Transaction characteristics (ACID characteristics)

A: Atomicity (Atomicity)

Transaction is the logical unit of work of the database, the transaction includes all or none of the operations.

B: Consistency (Consistency)

The result of the execution of the transaction must be to make the database from a consistent state to another consistent state. Consistency and atomicity are closely related.

C:Isolation

The execution of a transaction cannot be interfered with by other transactions.

D:Durability (Durability)

Once a transaction is committed, its changes to the data in the database should be permanent.

Note:Transaction is the basic unit of recovery and concurrency control. The basic concept of the above is also seen somewhere.

Below is an example:

Suppose a bank database has two tables, checking table (checking) and storage table (saving), now to transfer 10 million from A's checking account to his savings account, then minimum three steps are required.

1. checking the checking account balance is higher than 10 million

2. subtracting 10 million from the checking account

3. adding 10 million to the saving account

The above three steps have to be in a single transaction, and if any of the steps fails, all the steps have to be rolled back.