if object_id('表a') is not null drop table 表a go if object_id('表b') is not null drop table 表b go create table 表a(name varchar(20) not null) create table 表b(name varchar(20))begin try begin tran insert into 表a select null insert into 表b select 'c' commit tran end try begin catch rollback end catch --全部回滚set xact_abort on begin try begin tran insert into 表a select 'a' insert into 表b select 'c' select * from oooo --高级别错误 设置xact_abort,否则不会回滚 commit tran end try begin catch rollback end catchselect * from 表a select * from 表b
set xact_abort on 关键在这句上
SQL Server 2000好像用不了,请问各位怎么解决这个问题啊
当 SET XACT_ABORT 为 ON 时,如果执行 Transact-SQL 语句产生运行时错误,则整个事务将终止并回滚。当 SET XACT_ABORT 为 OFF 时,有时只回滚产生错误的 Transact-SQL 语句,而事务将继续进行处理。如果错误很严重,那么即使 SET XACT_ABORT 为 OFF,也可能回滚整个事务。OFF 是默认设置。编译错误(如语法错误)不受 SET XACT_ABORT 的影响。对于大多数 OLE DB 提供程序(包括 SQL Server),必须将隐式或显示事务中的数据修改语句中的 XACT_ABORT 设置为 ON。唯一不需要该选项的情况是在提供程序支持嵌套事务时。有关详细信息,请参阅 分布式查询和分布式事务。SET XACT_ABORT 的设置是在执行或运行时设置,而不是在分析时设置。
drop table 表a
go
if object_id('表b') is not null
drop table 表b
go
create table 表a(name varchar(20) not null)
create table 表b(name varchar(20))begin try
begin tran
insert into 表a select null
insert into 表b select 'c'
commit tran
end try
begin catch
rollback
end catch
--全部回滚set xact_abort on
begin try
begin tran
insert into 表a select 'a'
insert into 表b select 'c'
select * from oooo --高级别错误 设置xact_abort,否则不会回滚
commit tran
end try
begin catch
rollback
end catchselect * from 表a
select * from 表b
关键在这句上