C# C语言中的事务并发#
用户1:C# C语言中的事务并发#,c#,sql,concurrency,transactions,nolock,C#,Sql,Concurrency,Transactions,Nolock,用户1: begin tran select * from items with(nolock); insert into orders (odate) values(getdate()); insert into OrderData values((select max(orderid) from Orders with(nolock)),1,1); update Items set qih=qih-1 where item_id=1; select * from OrderData whe
begin tran
select * from items with(nolock);
insert into orders (odate) values(getdate());
insert into OrderData values((select max(orderid) from Orders with(nolock)),1,1);
update Items set qih=qih-1 where item_id=1;
select * from OrderData where oid=(select max(orderid) from Orders with(nolock));
insert into OrderData values((select max(orderid) from Orders with(nolock)),2,1);
update Items set qih=qih-1 where item_id=2;
select * from OrderData where oid=(select max(orderid) from Orders with(nolock));
commit tran;
用户2:
begin tran
select * from items with(nolock);
insert into orders (odate) values(getdate());
insert into OrderData values((select max(orderid) from Orders with(nolock)),1,1);//in here waiting this user
在提交user1之后。用户2正在执行最后一条语句
但是我想执行user 2最后一条语句,不等待。我该怎么做呢
请帮帮我。在不观察锁的情况下读取是可以支持的,因为最坏的情况是,您会对请求
nolock
的SPID造成数据完整性问题(幻像/不可重复读取)-这很好:它是自己造成的
在不观察锁的情况下写入是不受支持的。因为这将允许您对其他SPID造成数据完整性问题。这绝对不行
基本上如此;就我所知,你不能。你得等一下才能拿到锁
<> P>避免锁定延迟的最佳方法是确保事务完成必要的最小工作以确保一致的更改(并且在事务的中间没有外部操作)。