普遍认为存储过程会自动实现事务操作,其实不然。存储过程只是提供的事务操作的支持。要实现事务操作,还得自己实现。
需要设置 SET XACT_ABORT { ON | OFF }
示例
create proc testproc
as
SET XACT_ABORT on
begin tran
insert into tableA (field1) values ('aa')
insert into tableB (field1) values ('bb')
commit tran
SET XACT_ABORT off