SQL2005查詢死鎖的表和具體的語句

2022-01-11 15:07:37 字數 1016 閱讀 3587

查是哪個程序死鎖了哪些表

select request_session_id spid,object_name(resource_associated_entity_id) tablename

from sys.dm_tran_locks where resource_type='object'

下面的**是可以看到死鎖的語句

use master

godeclare @spid int,@bl int

declare s_cur cursor for

select 0 ,blocked

from (select * from sysprocesses where blocked>0 ) a

where not exists(select * from (select * from sysprocesses where blocked>0 ) b

where a.blocked=spid)

union select spid,blocked from sysprocesses where blocked>0

open s_cur

fetch next from s_cur into @spid,@bl

while @@fetch_status = 0

begin

if @spid =0

select '引起資料庫死鎖的是:

'+ cast(@bl as varchar(10)) + '程序號,其執行的sql語法如下'

else

select '程序號spid:'+ cast(@spid as varchar(10))+ '被' + '

程序號spid:'+ cast(@bl as varchar(10)) +'阻塞,其當前程序執行的sql語法如下'

dbcc inputbuffer (@bl )

fetch next from s_cur into @spid,@bl

endclose s_cur

deallocate s_cur

分享SQL2005 查詢表結構的SQL語句

1 select 2 case when a.colorder 1then d.name else end as 表名,如果表名相同就返回空 syscolumns 表字段資訊表 a sysobjects d 3 a.colorder as 字段序號,4 a.name as 欄位名,5 case wh...

sql2005 的樹形遞迴查詢

在sqlserver中從2005開始支援樹形遞迴查詢,其方法如下 從給定的根節點 可以是多個 向下查詢,直到所有子節點 with myt2 as select from 表名 where 根節點查詢條件 union all select 表名.from myt2 inner join 表名 on m...

sql2005表的基本操作

use caowen exec sp help dep 這是檢視資料庫表的結構 select from sysfiles 這是檢視資料庫檔案 這是修改資料庫檔案 alter database caowen modify file name caowenndf1 size 65mb 這裡指定的檔案的大...