Mysql's transaction operations have long been intended to be written, and I have forgotten it. In fact, it is very simple to explain the three commands starttransactioncommitrollback: starttransaction; that is, you must remember to write and then commit before starting the Transaction Tracking command; this means that if you confirm the submission, you cannot roll back when you execute this command.
Mysql transactions have long been written and forgotten. In fact, it is very simple to explain the three commands start transaction commit rollback: start transaction; before starting the transaction tracing command, you must remember to write and then commit. This means that you can't roll back when you confirm the submission.
Mysql transaction operations
I have long wanted to write it. I have forgotten it. It's actually very simple.
Just three commands
Start transaction
Commit
Rollback
Now let's explain:
Start transaction;
Is the command to start Transaction Tracking.
Remember to write before you start
Then
Commit;
This means that if you confirm the submission, you cannot roll back when you execute this command, which is equivalent to the completion of the execution.
Last
Rollback;
This command is very simple. It rolls back to the status when starting transaction.
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; (if you don't want to roll back, you can use commit)
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)