MySQL Things roll back

Source: Internet
Author: User
Tags rollback savepoint

#commit and rollback are used to ensure that the database has enough space left;
#commi, rollback can only be used for DML operations, that is, insert, UPDATE, delet;
#rollback操作撤销上一个commit, rollback after the transaction.

CREATE TABLE Test
(
prod_id varchar (TEN) is not NULL,
Prod_desc varchar (+) NULL,
Cost decimal (6,2) null
);

#禁止自动提交
Set autocommit=0;

#设置事务特性, must be set before all transactions begin
#set transaction Read only; #设置事务只读
Set transaction read write; #设置事务可读, write

#开始一次事务
Start transaction;
INSERT INTO Test
VALUES (' 4456 ', ' Mr Right ', 46.97);
Commit #位置1

INSERT INTO Test
VALUES (' 3345 ', ' Mr Wrong ', 54.90);
Rollback #回到位置1, (position 2); last Commit

INSERT INTO Test
VALUES (' 1111 ', ' Mr Wan ', 89.76);
Rollback #回到位置2, last rollback place.

#测试保存点savepoint
SavePoint point1;
Update test
Set prod_id=1;
Rollback to Point1; #回到保存点point1

Release SavePoint point1; #删除保存点

drop table test;

MySQL Things roll back

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.