事务区间内是原子操作么?需要锁么?
begin trans
--插入:
insert [Goods_Deal](Id,[Stuff],Price)
select a.*from [Goods_PriceReport] a
inner join [Goods_Order] b on a.Id=b.Id and a.[Stuff]=b.[Stuff]
where a.Price>=b.Price
--删除:
delete from [Goods_Order] where Id in(select Id from(
select a.*from [Goods_PriceReport] a
inner join [Goods_Order] b on a.Id=b.Id and a.[Stuff]=b.[Stuff]
where a.Price>=b.Price )a
)
commit trans
上面的语句会发生这种事么?
假如insert后突然新添加了一条order,那么接下来的delete肯下会执行,但可能这条order被删除了,但Deal表中没有
需要锁表么?怎么锁?
[解决办法]
可以考虑把第一个insert的id记录下来,然后删掉你记录的id。
[解决办法]
不需要的
[解决办法]
这哥没有必要锁表的
[解决办法]
是不是事务自动锁表?
[解决办法]
这个不需要锁表,加在BEGIN 和COMMIT之间的语句,只有执行到COMMIT之后数据才会真正写到数据库中,期间相关资源是申请锁的,不会出现你说的情况的。
[解决办法]
象你写的就已可以了,不用额外加锁
[解决办法]
iso隔离级别是uncommit read就会出现那种情况。