帮忙看个事务 问题
插入重复数据不回滚继续执行Update,是什么造成的
sql+=@"BEGIN TRANSACTION begin if not exists(select * from B_ArchiveList where relationInfo=@relation and status='true') begin Insert into B_ArchiveList(archiveName,relationInfo,bolNecessary,createDate,modifyDate) values(@name,@relation,@necessary,@createDate,@modifyDate) end if @@error<>0 begin ROLLBACK TRANSACTION return end end begin "; for(int i=0;i<list.Count;i++) { sql+=@" update T_PersonInfo set stateFlag=@stateFlag"+i+" where stateFlag=@state"+i; } sql+=@" if @@error<>0 begin ROLLBACK TRANSACTION return end end COMMIT TRANSACTION ";
begin Insert into B_ArchiveList ... if @@error<>0 begin ROLLBACK TRANSACTION return end end
[解决办法]
这个理解上来说只能是@@ERROR = 0了这样才能往下走。但为什么没有出错我们没有办法分析。
退一步讲,以下这个变动好像也没有意义。。。
begin Insert into B_ArchiveList ... if @@error<>0 begin ROLLBACK TRANSACTION return end end