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
2, directly with SET to change the MySQL automatic submission mode:
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