sybase SET CHAINED OFF與SET CHAINED ON兩種事務模式的區別

默認的是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>sql

相關文章
相關標籤/搜索