MYSQL basics: basic operations for transaction processing

Source: Internet
Author: User
Tags savepoint
MYSQL Getting started: link to basic transaction processing: MYSQL Getting started: Basic operations http://www.2cto.com/database/201212/ 173868.html MYSQL getting started 2: search using regular expressions http://www.2cto.com/database/201212/ ... MYSQL Getting started: Basics of transaction processing link: MYSQL Getting started: Basic operations http://www.2cto.com/database/201212/ 173868.html MYSQL getting started 2: search using regular expressions http://www.2cto.com/database/201212/ 173869.html MYSQL 3: full text search http://www.2cto.com/database/201212/ 173873.html MYSQL getting started 4: MYSQL data types http://www.2cto.com/database/201212/ Step 5: MYSQL character set http://www.2cto.com/database/201212/ 175541.html MYSQL getting started 6: MYSQL operators http://www.2cto.com/database/201212/ 175862.html: MYSQL common functions http://www.2cto.com/database/201212/ 175864.html: basic database and table operations http://www.2cto.com/database/201212/ 175867.html MYSQL Getting started: simple indexing operations http://www.2cto.com/database/201212/ 176772.html MYSQL Getting started: Basic View operations http://www.2cto.com/database/201212/ 176775.html MYSQL getting started 11: basic trigger operations http://www.2cto.com/database/201212/ 176781.html MYSQL Getting started: basic operations of stored procedures http://www.2cto.com/database/201212/ 177380.html MYSQL basics: basic operations for custom functions http://www.2cto.com/database/201212/ 177382.html MYSQL getting started 14: basic operations on cursors http://www.2cto.com/database/201212/ 177384. The html transaction processing (transaction processing) can be used to maintain the integrity of the database. it ensures that batch MySQL operations are either fully executed or not executed at all. Www.2cto.com, but not all database engines support transaction processing. MyISAM and InnoDB are two of the most commonly used engines. The former does not support clear transaction processing management, while the latter does. 1. Terms Related to transaction processing transactions (transaction) refer to a group of SQL statements; rollback refers to the process of revoking a specified SQL statement; commit) writing unstored SQL statement results to the database table; savepoint refers to the temporary placeholder (placeholder) set in transaction processing ), you can release rollback for it (unlike the rollback process for the entire transaction ). 2. the key to controlling transaction processing is to extract SQL statement components into logical blocks and specify when data should be rolled back and when data should not be rolled back. 1. start transaction. use the preceding statement to identify the START of the TRANSACTION. 2. use the ROLLBACK command to roll back (undo) the MySQL statement. The following example starts a TRANSACTION, then, all contents in the table test_inn are deleted, and the table content is displayed, indicating that the table has been cleared. However, after the ROLLBACK transaction is executed, the data in the table is re-queried. The data in the table is still: [SQL] mysql> start transaction; mysql> delete from test_inn; mysql> select * from test_inn; Empty set (0.00 sec) mysql> rollback; mysql> select * from test_inn; + ------ + ------------ + | id | birthday | + ------ + ------------ + | 1 | 2012-12-12 | 1 | 0000-00-00 | 1 | 2012-12-00 | 1 | 0000-00 -00 | + ------ + ------------ + mysql> show create table test_inn; + ---------- + ----------------------- ----- | Table | Create Table + ---------- + -------------------------- | test_inn | create table 'test _ inn '('id' int (11) default null, 'birthday' date default null) ENGINE = InnoDB default charset = latin1 | + ---------- + ---------------------------- Note: In the preceding example, table test_inn uses the InnoDB ENGINE. if a table using the MyISAM ENGINE performs the preceding operations, even after ROLLBACK, we can find that the data is actually cleared. 3. generally, MySQL statements using COMMIT are implicitly submitted (implicit commit), that is, the COMMIT (write or save) operation is automatically performed. However, commit is not performed implicitly in the transaction processing block. The COMMIT statement is required for explicit submission. Example: [SQL] mysql> start transaction; mysql> delete from test_inn; mysql> commit; when a COMMIT or ROLLBACK statement is executed, the started transaction is automatically closed.
4. use reserved points in order to support the rollback of some transactions, the reserved points must be placed in a proper position in the transaction processing block. Create retention point: SAVEPOINT sap_name; roll back TO retention point: rollback to sap_name; RELEASE retention point: RELEASE sp_name; retention point can also be completed in the transaction processing (execute a ROLLBACK or COMMIT) and then automatically released. 5. change the default submission behavior SET autocommit = 0. the autocommit flag is for each connection, not the server. Reference: MySQL required knowledge
 

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.