我们可以在tranasction(rollback,commit)中执行ddl命令吗?

问题描述:

我有一个疑问我需要明确的答案是或否我们是否可以在交易中使用ddl命令?



再一次



我们是否可以在函数中执行dml语句请回复此问题。



我尝试过:



开始转换

trucate table emp

rollback

I have one doubt i need clear cut answer yes or no whether we can use ddl command in transaction or not?

one more

whether we can execute dml statments in function please anser this quetion.

What I have tried:

begin trans
trucate table emp
rollback

我不太确定其他DBMS所以我会在答案中关注SQL Server。



我可以使用DDL吗?交易?

,但并非所有人都被允许!请参阅文档 [ ^ ]获取完整的语句列表在交易中不允许。正如您已经发现的那样,TRUNCATE可以回滚得很好。



我可以在函数中使用DDL吗?

。您甚至不允许在函数中执行插入或删除操作。请参阅文档此处 [ ^ ]或 here [ ^ ]了解更多信息。
I'm no so certain about other DBMS so I will focus on SQL Server in my answer.

Can I use DDL in a transaction?
YES, but not all are allowed! Please see the documentation[^] for a complete list of statements that are not allowed in transactions. As you already found out TRUNCATE can be rolled back just fine.

Can I use DDL in a functions?
NO. You are not even allowed to perform inserts or deletes in a function. Please refer to documentation here[^] or here[^] for more information.