Transactions can be defined in many, many different ways. In fact, a transaction is a unit of work performed by a database operation.
Transaction Characteristics
In a database system, a transaction refers to a complete logical process consisting of a series of database operations. For example, bank transfer, deduction of the amount from the original account, and the addition of the amount to the target account, the sum of the two database operations, constitutes a complete logical process that cannot be split. This process is called a transaction and has an acid characteristic.
- Atomicity (atomicity): All operations in a transaction (transaction) are either complete or not complete and do not end up in the middle of a link. When an error occurs during execution, the transaction is rolled back (Rollback) to the state before the transaction begins, as if the transaction had never been executed.
- Consistency (consistency): the integrity of the database is not compromised until the transaction begins and after the transaction has ended. This means that the data being written must fully conform to all of the preset rules, which include the accuracy of the data, the concatenation, and the subsequent database's ability to perform the scheduled work spontaneously.
- Isolation (Isolation): the interrelationship that occurs when two or more transactions concurrently access the same data in a database that refers to queries and modified operations. Transaction isolation is divided into different levels, including read UNCOMMITTED, Read Committed, REPEATABLE READ (repeatable Read), and serialization (Serializable).
- Persistence (Durability): After the transaction completes, the transaction changes made to the database are persisted in the database and are complete.
transaction type
- Automatically committed transactions--Each individual statement is a transaction
- Show declared transactions-this transaction is marked with BEGIN Tran, and is rollback TRAN or a commit tran the end of the statement.
- Implied transaction - SQL Server starts a new transaction automatically after the current transaction is committed or rolled back, and the new transaction is started by the system when the user executes commit or rollback. This creates a continuous chain of transactions.
SQL Server common transaction operations contain three types of
- Begin TRANSACTION--transaction start checkpoint
- ROLLBACK TRANSACTION--rollback of data to the beginning of a transaction due to an error
- COMMIT TRANSACTION--Save the data to the database
What is a transaction