为什么我SQL加了事务处理,却不能阻止INSERT
我想保证数据的完整行 ,其中update更新一定会报错。SQL内部加了约束。为啥事务不能阻止insert
begin transaction
declare @errorSum int --定义变量,用于累计事务执行过程中的错误
/**//*--转帐--*/
update bank set currentMoney=currentMoney-800 where customerName='张三'
set @errorSum=@errorSum+@@error --累计是否有错误
update bank set currentMoney=currentMoney+800 where customerName='李四'
set @errorSum=@errorSum+@@error --累计是否有错误
INSERT INTO bank VALUES('王五',300)
COMMIT transaction