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