1. 程式人生 > 實用技巧 >Sql server 鎖表查詢Sql

Sql server 鎖表查詢Sql

查詢SQLServer表被鎖的型別

declare@dbnamenvarchar(200),@objidnvarchar(200) set@dbname='PETTY_CASH_ORIGIN' set@objid='PC_INVOICE_MASTER' Selecta.req_spid,db_name(a.rsc_dbid)as資料庫,object_name(a.rsc_objid)as表, 資源型別=casea.rsc_typewhen1then'NULL資源(未使用)' when2then'資料庫' when3then'檔案' when4then'索引' when5then'表' when6then'頁' when7then'鍵' when8then'擴充套件盤區' when9then'RID(行ID)' when10then'應用程式' end, 鎖模式=casea.req_modewhen0then'Null' when1then'Sch-S(架構性定性)' when2then'Sch-M(架構修改)' when3then'S(共享鎖)' when4then'U更新' when5then'X排它鎖' when6then'IS意向共享' when7then'' end, 鎖狀態=casea.req_statuswhen1then'已授權' when2then'正在轉換' when3then'正在等待' end, 物件型別=casea.req_ownertypewhen1then'事務' when2then'遊標' when3then'會話' end frommaster.dbo.syslockinfoasa,master.dbo.sysprocessesasb wherea.rsc_dbid=b.dbidANDa.req_spid=b.spid ANDa.rsc_type=5andobject_name(a.rsc_objid)=@objidanddb_name(a.rsc_dbid)=@dbname orderbyreq_spid

1,檢視那個表死鎖

select object_name(resource_associated_entity_id) as tableName, request_session_id as pid from sys.dm_tran_locks
where resource_type = 'OBJECT'

2,結束死鎖的程序

kill 70