/**/
/*****隱式事務*****/
/**/ /*****sql 的行為就類似一個快餐店,當你需要時,必須付款,
如果返回又想要一些額外的食物,你必須再付款。
ANSI行為就像去了飯店。你訂湯,服務員為你記賬,當你訂更多的東西時,他們負責添加到賬上
,最后你付款。
*****/
/**/ /*****#1*****/
set implicit_transactions off
go
if exists ( select * from dbo.sysobjects where id = object_id ( ' nesttran ' ))
drop table nesttran
go
create table nesttran(id int identity ( 1 , 1 ) not null ,transcount int )
go
insert nesttran
values ( @@trancount )
go
select * from nesttran where id = 1
select @@trancount as transcount
/**/ /*****#2*****/
begin tran
insert nesttran
values ( @@trancount )
commit
go
select * from nesttran where id = 2
select @@trancount as transcount
/**/ /*****#3*****/
begin tran
begin tran
insert nesttran
values ( @@trancount )
select @@trancount as transcount
commit
select @@trancount as transcount
commit
go
select * from nesttran where id = 3
select @@trancount as transcount
/**/ /*****#4*****/
set implicit_transactions on
go
insert nesttran
values ( @@trancount )
commit
go
select @@trancount as transcount
select * from nesttran
where id = 4
select @@trancount as transcount
commit
select @@trancount as transcount
go
/**/ /*****#5*****/
insert nesttran
values ( @@trancount )
begin tran
insert nesttran
values ( @@trancount )
commit
commit
go
select @@trancount as transcount
select * from nesttran
where id = 5 or id = 6
select @@trancount as transcount
commit
select @@trancount as transcount
/**/ /*****#7*****/
set implicit_transactions off
drop table nesttran
go
/**/ /*****sql 的行為就類似一個快餐店,當你需要時,必須付款,
如果返回又想要一些額外的食物,你必須再付款。
ANSI行為就像去了飯店。你訂湯,服務員為你記賬,當你訂更多的東西時,他們負責添加到賬上
,最后你付款。
*****/
/**/ /*****#1*****/
set implicit_transactions off
go
if exists ( select * from dbo.sysobjects where id = object_id ( ' nesttran ' ))
drop table nesttran
go
create table nesttran(id int identity ( 1 , 1 ) not null ,transcount int )
go
insert nesttran
values ( @@trancount )
go
select * from nesttran where id = 1
select @@trancount as transcount
/**/ /*****#2*****/
begin tran
insert nesttran
values ( @@trancount )
commit
go
select * from nesttran where id = 2
select @@trancount as transcount
/**/ /*****#3*****/
begin tran
begin tran
insert nesttran
values ( @@trancount )
select @@trancount as transcount
commit
select @@trancount as transcount
commit
go
select * from nesttran where id = 3
select @@trancount as transcount
/**/ /*****#4*****/
set implicit_transactions on
go
insert nesttran
values ( @@trancount )
commit
go
select @@trancount as transcount
select * from nesttran
where id = 4
select @@trancount as transcount
commit
select @@trancount as transcount
go
/**/ /*****#5*****/
insert nesttran
values ( @@trancount )
begin tran
insert nesttran
values ( @@trancount )
commit
commit
go
select @@trancount as transcount
select * from nesttran
where id = 5 or id = 6
select @@trancount as transcount
commit
select @@trancount as transcount
/**/ /*****#7*****/
set implicit_transactions off
drop table nesttran
go