MySQL transaction rollback

Source: Internet
Author: User

MySQL needs to make sure that the storage engine is InnoDB before using the transaction, such as deleting a person's data, deleting some data that is related to this person, and then using the transaction, a deletion error, and the entire delete transaction is canceled.

Transaction rollback steps:

/* Create roll Table */
CREATE TABLE Roll (
ID int unsigned primary key auto_increment comment ' primary key ',
Names varchar (+) NOT null default ' comment ' name '
) CHARSET =utf8 ENGINE =innodb;

Engine for InnoDB;

/* Because there are too few fields and an amount of ownership is inserted */

ALTER TABLE Roll ADD money float NOT null default ' 0.0 ' comment ' own amount ';

/* Insert Data */
INSERT into Roll VALUES
(null, ' Lily ', ' 1000.8 '),
(null, ' Lucy ', ' 2009.7 '),
(NULL, ' liming ', ' 3009 ');

The table is as follows:

The rollback transaction steps are as follows:

First, start a transaction code as follows:

  Make a save point a code as follows:

Execute a Delete action code as follows:

Query the contents of the table again:

If you feel that there is a problem with performing the operation, you can choose to roll back to a save point and finally query the data back to the start status code as follows:

Note: If you feel the code is fine, you can execute a commit and the transaction cannot be rolled back after execution.

MySQL transaction rollback

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.