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.
精彩评论