Mysql transaction operations

Source: Internet
Author: User
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)

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.