Classes used by transactions

Source: Internet
Author: User
Transaction processing transactions are database operations that combine logical units in a group. errors may occur during system execution, but Transactions Control and maintain the consistency and integrity of each database. The main feature of transaction processing is that tasks are either completely completed or not completed. When writing some records, either write all the records or do nothing

Transaction processing transactions are database operations that combine logical units in a group. errors may occur during system execution, but Transactions Control and maintain the consistency and integrity of each database. The main feature of transaction processing is that tasks are either completely completed or not completed. When writing some records, either write all the records or do nothing

Transaction Processing

Transaction Processing

A transaction is a database operation that combines logical work units in a group. errors may occur during system execution. The Hong Kong Vm, however, controls and maintains the consistency and integrity of each database. The main feature of transaction processing is that tasks are either completely completed or not completed. When writing some records, either write all the records or write nothing. If a failure occurs when writing a record, other data already written in the transaction will be rolled back. A transaction may consist of many individual tasks.

A common example of simple transactions: transferring money from account A to account B involves two tasks: the Hong Kong Vm, that is, getting money from account; save the money to account B. The two tasks either succeed at the same time or fail at the same time, and are rolled back to keep the account in the same status as before. Otherwise, an operation may fail due to power failure or network interruption. Therefore, the rows in a table may be updated, but the rows in the table may not be updated. If the database supports transactions and Hong Kong servers, database operations can be combined into a transaction to prevent database inconsistencies due to these events.

The ACID attribute of the transaction is as follows.

L Atomicity: all operations of a transaction are atomic units of work. Modifications to the data of a transaction are either executed or not executed. Atomicity eliminates the possibility of a subset of system processing operations.

L Consistency: data is converted from one correct state to another. When the transaction is completed, all data must be consistent. In the relevant database, all rules must be applied to the modification of transactions to maintain the integrity of all data. When the transaction ends, all internal data structures must be correct. In the example of deposit withdrawal, the logic rule is that money cannot be generated or sold out of thin air, and a corresponding offset entry must be generated for each (Revenue and Expenditure) entry, to ensure that the account is flat.

L Isolation: the modifications made by the concurrent transactions must be isolated from those made by any other concurrent transactions. View the status of the data in the data hours, either the status before the transaction modifies it, or the status after the transaction modifies it. A simple understanding is to prevent multiple concurrent updates from interfering with each other. Transactions are isolated from other transaction operations when operating data. Isolation is generally achieved through the locking mechanism.

L Durability: after a transaction is completed, its impact on the system is permanent. The submitted changes still exist in the event of a fault.

For transaction development, the. NET platform also provides several simple and convenient transaction mechanisms. Both in terms of functionality and performance provide excellent enterprise-level transaction support.

. NET developers can use the following five transaction mechanisms:

L SQL and stored procedure-level transactions.

L ADO. NET-level transactions.

L ASP. NET page-level transactions.

L enterprise-level service COM + transactions.

L System. Transactions transaction processing.

These five transaction mechanisms have their own advantages and disadvantages, including performance, code quantity, and deployment settings. Developers can select the corresponding transaction mechanism based on the actual situation of the project.

5.4.1 SQL and stored procedure-level transactions

Database transactions are the basis of other transaction models. When a transaction is created, different database systems have their own rules. By default, SQL Server works in auto-submit mode. Each statement is submitted immediately after execution. In contrast, Oracle requires you to include a submit statement. However, when a statement is executed through ole db, the subsequent commit action is appended. For example:

DECLARE @ TranName VARCHAR (20 );

SELECT @ TranName = 'mytransaction ';

Begin transaction @ TranName;

GO

USE AdventureWorks;

GO

Delete from AdventureWorks. HumanResources. JobCandidate

WHERE JobCandidateID = 13;

GO

Commit transaction MyTransaction;

GO

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.