【发布时间】:2010-11-21 08:50:40
【问题描述】:
MySQL 是否允许使用嵌套事务?
【问题讨论】:
-
mysql 不支持嵌套事务
标签: mysql transactions nested-transactions
MySQL 是否允许使用嵌套事务?
【问题讨论】:
标签: mysql transactions nested-transactions
InnoDB 支持SAVEPOINTS。
您可以执行以下操作:
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
---
【讨论】:
来自 MySQL 文档:
事务不能嵌套。这是当您发出 START TRANSACTION 语句或其同义词之一时对任何当前事务执行的隐式提交的结果。 https://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html
【讨论】: