小编sha*_*son的帖子

选择屏蔽问题

数据库没有响应简单的选择语句,如

select * from table
Run Code Online (Sandbox Code Playgroud)

我注意到sys.dm_os_waiting_tasks一个会话被阻塞,阻塞会话指向一个使用 lock & Tran 的存储过程,如下所示

    BEGIN TRAN

declare @min numeric ,@com numeric

select top 1  @com=companyid from tblcompanies
order by newid()



select @min=min(productid) from tblproducts(UPDLOCK)
where companyid=@com and (lockstatus<>1 or lockstatus is null )


update tblproducts
set lockStatus='1'
where productid>=@min and productid<@min+4

select distinct top 4 s.productname,s.productid,s.companyid,r.Type,r.requestType,r.UserID
from tblcompanydetail rd inner join tblproducts s
on rd.productid=s.productid
inner join tblcompanies r
on r.companyid=s.companyid
where s.productid>=@min and s.productid<@min+4


if @@error >0 rollback tran

commit tran …
Run Code Online (Sandbox Code Playgroud)

sql-server-2005 sql-server

4
推荐指数
1
解决办法
279
查看次数

标签 统计

sql-server ×1

sql-server-2005 ×1