mysql 中的保存点提交回滚

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1294372/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:54:51  来源:igfitidea点击:

savepoint commit rollback in mysql

mysql

提问by Sakthivel

how can we use commit, rollback and savepoint in mysql ?

我们如何在 mysql 中使用提交、回滚和保存点?

回答by Quassnoi

CREATE TABLE t_test (id INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;

START TRANSACTION;

INSERT
INTO    t_test
VALUES  (1);

SELECT  *
FROM    t_test;

 id
---
  1

SAVEPOINT tran2;

INSERT
INTO    t_test
VALUES  (2);

SELECT  *
FROM    t_test;

 id
---
  1
  2

ROLLBACK TO tran2;

SELECT  *
FROM    t_test;

 id
---
  1

ROLLBACK;

SELECT  *
FROM    t_test;

 id
---

回答by vennila

mysql> start transaction;
mysql> savepoint id;

Here you alter the table data and then:

在这里更改表数据,然后:

mysql> rollback to savepoint id;

View the data and finally:

查看数据,最后:

mysql> release savepoint id;