使用create语句的InnoDb交易 [英] InnoDb transactions with create statements

查看:86
本文介绍了使用create语句的InnoDb交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

事务中是否允许使用诸如CREATE TABLE tbl_name .....之类的sql语句.

Are sql statements such as CREATE TABLE tbl_name ..... allowed in transactions.

例如:

begin;

CREATE TABLE .......;

sdfghjk;

rollback;

尽管事务中的语句失败,但仍然创建了表,并在最后进行了回滚.如果事务中的语句失败,是否可以防止创建表?

The table is still created despite a statement in the transaction failing, and a rollback at the end. Is there a way to prevent the table from being created if a statement in the transaction fails?

推荐答案

在事务中允许使用DDL语句,但通常不受事务影响.从MySQL文档中可以回退的内容:

DDL statements are allowed within transactions, but are not generally impacted by the transactions. From the MySQL Documentation on what can and cannot be rolled back:

某些语句无法回滚.通常,这些包括数据 定义语言(DDL)语句,例如创建或 删除数据库,即创建,删除或更改表或存储的数据库 例程.

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.

您应设计您的交易不包含此类声明.如果 您在无法滚动的交易中提早发出了对帐单 返回,然后另一条语句稍后失败, 在这种情况下,不能通过发出ROLLBACK来回滚事务 声明.

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.

这篇关于使用create语句的InnoDb交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆