BEGIN TRY BEGIN TRAN ...語句COMMIT TRAN END TRY BEGIN CATCH SELECT ERROR_MESSAGE() ROLLBACK TRAN END CATCH
或 SET XACT_ABORT ON BEGIN TRAN ...語句COMMIT TRAN 当 SET XACT_ABORT 为 ON 时,如果执行 Transact-SQL 语句产生运行时错误,则整个事务将终止并回滚。
begin tran delete from tb1 delete from tb2 delete from tb3 if @@error<>0 rollback tran else commit tran
begin tran delete from tb1 delete from tb2 delete from tb3 commit tran
set xact_abort on begin tran delete from tb1 ... delete from tb2 ... delete from tb3 ... commit tran
BEGIN TRY BEGIN TRAN DELETE FROM TB WHERE 条件DELETE FROM TB WHERE 条件DELETE FROM TB WHERE 条件 COMMIT TRAN END TRY BEGIN CATCH SELECT ERROR_MESSAGE() ROLLBACK TRAN END CATCH
begin tran delete tb where id=1 delete tb where id=2 delete tb where id=3 commit
delete from ...
delete from ...
delete from ...if @@error <>0
rollback tran
else
commit tran
delete tb ...
delete tb ...
delete tb ...
commit
BEGIN TRAN
...語句COMMIT TRAN
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE()
ROLLBACK TRAN
END CATCH
SET XACT_ABORT ON
BEGIN TRAN
...語句COMMIT TRAN
当 SET XACT_ABORT 为 ON 时,如果执行 Transact-SQL 语句产生运行时错误,则整个事务将终止并回滚。
delete from tb1
delete from tb2
delete from tb3
if @@error<>0
rollback tran
else
commit tran
delete from tb1
delete from tb2
delete from tb3
commit tran
set xact_abort on
begin tran
delete from tb1 ...
delete from tb2 ...
delete from tb3 ...
commit tran
BEGIN TRY
BEGIN TRAN
DELETE FROM TB WHERE 条件DELETE FROM TB WHERE 条件DELETE FROM TB WHERE 条件
COMMIT TRAN
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE()
ROLLBACK TRAN
END CATCH
begin tran
delete tb where id=1
delete tb where id=2
delete tb where id=3
commit
触发器是指一种在基表(还有其他数据库对象)被修改时自动执行的内嵌过程。
这是两个截然不同的概念,没有可比性。
delete tb ...
commit
set xact_abort on begin transactiondelete from table1 where
delete from table2 where
delete from table3 wherecommit transactiongo