默認的是off,SQL92標准默認是on.
如果是on,那麼會為一個SQL語句塊隱式開啟一個事務。
如果是off,除非你使用了begin tran,它不會主動為你開啟一個事務。
主要就這點區別,這種區別有時候還是很明顯的。
這是默認的chained off的效果:
d:\>isql -Uadventure -Siihero_ase
PassWord:
1> select * from t123
2> go
id col2
----------- --------------------------------
1 a
2 b
3 c
4 d
5 e
(5 rows affected)
1> select @@tranchained
2> go
-----------
0
(1 row affected)
1> insert into t123 values(6, 'f')
2> begin tran
3> delete from t123 where id=6
4> rollback tran
5> go
(1 row affected)
(1 row affected)
1> select * from t123
2> go
id col2
----------- --------------------------------
1 a
2 b
3 c
4 d
5 e
6 f
(6 rows affected)
1>
這是chained on的效果:
d:\>isql -Uadventure -Siihero_ase
PassWord:
1> set chained on
2> commit
3> go
1> insert into t123 values(7, 'g')
2> select @@trancount
3> go
(1 row affected)
-----------
1
(1 row affected)
1> begin tran
2> delete from t123 where id=7
3> select @@trancount
4> go
(1 row affected)
-----------
2
(1 row affected)
1> rollback tran
2> select @@trancount
3> go
-----------
1
(1 row affected)
1> select * from t123
2> go
id col2
----------- --------------------------------
1 a
2 b
3 c
4 d
5 e
6 f
(6 rows affected)
1>