MySQL's business operation
Long to write, has been forgotten, in fact, very simple
On three orders.
Start transaction
Commit
Rollback
Now to explain:
Start transaction;
is the command to start a transaction trail.
You must remember to write before you start
And then
Commit
This means that the confirmation of the submission, the implementation of this command can not be rollback, equivalent to the completion of execution.
At last
Rollback
This command is simple and rolls back to the state of the start transaction
Now for example
Mysql> select * from UserAccount;
+-----------+--------+-------------+
| AccountId | UserID | AccountName |
+-----------+--------+-------------+
| 1 | 2 | Zhifubao |
+-----------+--------+-------------+
1 row in Set (0.00 sec)
mysql> start transaction;
Query OK, 0 rows Affected (0.00 sec)
mysql> Update UserAccount Set UserID = 1;
Query OK, 1 row Affected (0.00 sec)
Rows matched:1 changed:1 warnings:0
Mysql> select * from UserAccount;
+-----------+--------+-------------+
| AccountId | UserID | AccountName |
+-----------+--------+-------------+
| 1 | 1 | Zhifubao |
+-----------+--------+-------------+
1 row in Set (0.00 sec)
mysql> rollback; (here if you don't want to roll back, use a commit; you can do it.)
Query OK, 0 rows affected (0.28 sec)
Mysql> select * from UserAccount;
+-----------+--------+-------------+
| AccountId | UserID | AccountName |
+-----------+--------+-------------+
| 1 | 2 | Zhifubao |
+-----------+--------+-------------+
1 row in Set (0.00 sec)