代碼
SET XACT_ABORT on
--建立測試表
create table tb(
id int not null constraint PK_sys_zj_fielddict primary key
,aa int)
--設定選項
SET XACT_ABORT on
--事務處理
begin tran
insert into tb values(1,1)
insert into tb values(1,1)
insert into tb values(2,1)
commit tran
GO
--顯示結果
/*--------注意
如果這樣寫的話,後面的語句不會被執行,如果要執行後面的語句,要在這句後面加上GO,僅查詢分析分析器支援,是以如果是在存儲過程中,要保證commit tran後面沒有其他語句,否則出錯時,其他語句不會被執行
-----------*/
select * from tb
drop table tb