Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Oracle_ transaction control statement

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

A transaction is a logical unit of database operation, which can contain one or more DML (data manipulation language), DDL (data definition language) and DCL (data Control language) statements in a transaction, which form a logical whole.

The execution of a transaction has only two results: either execute it all, bringing the database to a new state, or none at all and make no changes to the database.

There are two operations on a transaction: commit (COMMIT) and rollback (ROLLBACK).

When a transaction is committed, changes made to the database are permanently written to the database.

When the transaction is rolled back, all changes made to the database are undone, and the database is restored to its pre-operation state.

Transactions can be used to manipulate the database in any situation, including applications, stored procedures, triggers, and so on.

A transaction has four attributes, and the first letter of the four attributes is ACID.

These four attributes are:

Atomicity: transactions are either executed in full or not executed at all, and partial execution is not allowed.

Consistency: a transaction takes a database from one consistent state to another.

Isolation: the execution of one transaction is not affected by other transactions.

Durability: once a transaction is committed, it is permanently valid and is not affected by conditions such as shutdown.

A transaction can contain multiple DML statements, or a DDL statement, or a DCL statement.

The transaction begins with the first SQL statement and ends in one of the following situations:

Encountered the COMMIT or ROLLBACK command.

Encountered a DDL or DCL command.

The system has an error, exit, or crash.

In short, a transaction is a series of operations that can bring the system to a new state. If the transaction is committed, the database enters a new state, otherwise the database returns to the previous state of the transaction.

The advantage of using transactions in a database is that first of all, you can ensure the consistency of the data, and secondly, you can preview previous data changes before making permanent changes to the data, and you can group logically related operations.

There are two ways to control transactions, one is implicit control, the database management system decides whether to commit the transaction or roll back the transaction according to the actual situation; the download address springmvc integrates the mybatis framework source code

Another way is to explicitly control and place a COMMIT or ROLLBACK command at the end of the transaction to commit or roll back the transaction.

If it is implicit, the transaction will be committed automatically when it encounters a DDL command, such as CREATE, or encounters a DCL command, such as GRANT, or exits normally from SQL * Plus, even if no COMMIT or ROLLBACK command is issued.

If there is an abnormal exit from SQL*Plus or a system crash occurs, the system automatically rolls back the transaction.

If it is explicitly controlled, the transaction is committed at the end of the transaction through the COMMIT command, or the transaction is rolled back through a ROLLBACK command.

If the transaction is committed, the changes made to the database will be written to the human database.

If a transaction is rolled back, it is typically rolled back to the beginning of the transaction, that is, no changes are made to the database.

In Oracle, partial rollback of a transaction is allowed, that is, the transaction can be selectively rolled back to an intermediate point.

Part of the rollback is achieved by setting the save point (SAVEPOINT).

Several Savepoints can be set in a transaction through the SAVEPOINT command, so that the transaction can be selectively rolled back to a SavePoint.

When the user accesses the database, the data in the database is placed in the buffer, and the current user can browse the results of the data operation through the query operation.

If the transaction is not committed, other users will not see the modification result of the transaction.

When a user modifies the data in the table, the modified data is locked, and other users cannot modify the data until the user commits or returns the transaction.

If the COMMIT command is executed at the end of the transaction, the modifications to the data will be written to the database, the previous data will be permanently lost and cannot be recovered, other users can browse the modified results, the locks added on the data will be released, other users can perform new modifications to the data, and all Savepoints set in the transaction will be deleted

If a SavePoint is set in the transaction and the ROLLBACK command is executed at the end of the transaction to roll back to a SavePoint, the changes made by the DML statement after that SavePoint are discarded, but the changes made by the DML statement before the SavePoint are still not written to the database and can be committed or rolled back.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report