gpt4 book ai didi

mysql - 带有 create 语句的 InnoDb 事务

转载 作者:行者123 更新时间:2023-11-29 09:01:02 27 4
gpt4 key购买 nike

事务中是否允许使用 CREATE TABLE tbl_name ..... 等 sql 语句。

例如:

begin;

CREATE TABLE .......;

sdfghjk;

rollback;

尽管事务中的语句失败并且最后回滚,表仍然被创建。如果事务中的语句失败,是否有办法阻止创建表?

最佳答案

事务中允许使用 DDL 语句,但通常不受事务影响。来自 MySQL 文档,了解什么可以回滚,什么不可以回滚:

Some statements cannot be rolled back. In general, these include data definition language (DDL) statements, such as those that create or drop databases, those that create, drop, or alter tables or stored routines.

You should design your transactions not to include such statements. If you issue a statement early in a transaction that cannot be rolled back, and then another statement later fails, the full effect of the transaction cannot be rolled back in such cases by issuing a ROLLBACK statement.

Source

关于mysql - 带有 create 语句的 InnoDb 事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8620406/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com