MySQL's business operation

Source: Internet
Author: User
Tags commit rollback

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)

Related Article

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.