开发者

TSQL: comma combination, transaction?

开发者 https://www.devze.com 2022-12-22 18:20 出处:网络
Given the following: select * from a; select * from b; Are these two statements run in an implicit开发者_StackOverflow transaction?The default transaction mode in SQL Server is autocommit, unless

Given the following:

select * from a; 
select * from b;

Are these two statements run in an implicit开发者_StackOverflow transaction?


The default transaction mode in SQL Server is autocommit, unless you specify otherwise. This means that every statement is run in its own transaction; if one fails, all of the preceding statements still succeed.

You can change this with either a BEGIN TRAN statement (explicit transaction) or SET IMPLICIT_TRANSACTIONS ON (turns on implicit transactions). Note that if you enable implicit transactions, only the BEGIN is implicit - you still need to explicitly COMMIT.

It's also generally considered bad practice to use implicit transactions; it tends to lead to buggier scripts due to transactional boundaries not being clearly visible.

0

精彩评论

暂无评论...
验证码 换一张
取 消