sqlserver 数据库查询 数据库连接情况和 什么语句造成死锁

//查询数据库的链接情况

SELECT
request_session_id spid,
OBJECT_NAME(
resource_associated_entity_id
) tableName
FROM
sys.dm_tran_locks
WHERE
resource_type = 'OBJECT'


SELECT * FROM
[Master].[dbo].[SYSPROCESSES] WHERE [DBID]
IN
(
SELECT
[DBID]
FROM
[Master].[dbo].[SYSDATABASES]
WHERE
NAME='数据库名称'
)

//查询造成数据库死锁的语句

select er.session_id,CAST(csql.text AS varchar(255)) AS CallingSQL
from master.sys.dm_exec_requests er
WITH (NOLOCK)
CROSS APPLY MASTER.sys.fn_get_sql (er.sql_handle) csql
where er.session_id =68

posted on 2019-08-09 10:18  gfbppy  阅读(406)  评论(0编辑  收藏  举报

导航