(MySQL learning note 4) transaction opening, Commit, rollback

Source: Internet
Author: User

The following three points are to be noted for using transactions:

1. In MySQL, transactions are supported only by databases or tables that use the INNODB database engine.

2, transaction processing can be used to maintain the integrity of the database, to ensure that the batch of SQL statements are either all executed, or all do not execute.

3. Transactions used to manage Insert,update,delete statements


There are two main methods of MYSQL transaction processing:

1, with BEGIN, ROLLBACK, commit to achieve

    • begin a transaction

    • ROLLBACK Transaction rollback

    • Commit Transaction acknowledgement

2, directly with SET to change the MySQL automatic submission mode:

    • SET autocommit=0 prohibit auto-commit

    • SET autocommit=1 turn on auto-commit


For example:

SET autocommit = 0; Begin;insert into Km_xtyh (YHID,YHMC) VALUE (' asdjoi213hjsh ', ' John Doe '); COMMIT;

Interpretation:

The auto-commit is turned off and then the transaction is opened with "BEGIN" , and after the INSERT statement, there is no "commit" operation and there is no real commit, the data is only temporary Database (Note: There is already "John Doe" in the database), if the execution of the "COMMIT" statement, the data will be permanently inserted into the database;

If you do not execute "COMMIT" is another statement "ROLLBACK", then the record will not exist in the database, the data is not actually inserted successfully.

This article is from the "W1SW" blog, make sure to keep this source http://cfdeng.blog.51cto.com/9873532/1944349

(MySQL learning note 4) transaction opening, Commit, rollback

Related Article

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.