작동버젼 : SQL Sserver 2000, 2005 이상
사용방법 : 실행
주의사항 : Where절을 입맛에 맞게 수정 하여 사용
설 명 : 다른 명령에 의해 대기 상태인 명령어 발견
SQL Server 2000 버젼용
SELECT SPID ,Status ,LogiName AS Login ,HostName ,blocked AS BlkBy ,DB_NAME(dbid) AS DBName ,cmd AS Command ,cpu AS CPUTime ,physical_io AS DiskIO ,last_batch AS LastBatch ,program_name AS ProgramName ,DATEDIFF(MI, last_batch, GETDATE()) FROM master..sysprocesses WHERE SPID <> @@SPID AND DATEDIFF(SS, last_batch, GETDATE()) >= 5 AND ( Blocked <> 0 OR SPID IN ( SELECT blocked FROM master..sysprocesses WHERE blocked <> 0 AND blocked <> @@SPID ) ) ORDER BY SPID;SQL Server 2005 이상 버젼용
SELECT a.SPID ,a.Status ,a.LogiName AS Login ,a.HostName ,a.Blocked AS BlkBy ,DB_NAME(a.dbid) AS DBName ,a.Cmd AS Command ,a.Cpu AS CPUTime ,a.Physical_io AS DiskIO ,a.Last_Batch AS LastBatch ,a.Program_Name AS ProgramName ,b.Text FROM master.sys.sysprocesses AS a WITH(NOLOCK) CROSS APPLY master.sys.dm_exec_sql_text(a.Sql_Handle) AS b WHERE a.SPID <> @@SPID AND ( DATEDIFF(SS, a.Last_Batch, GETDATE()) >= 5 OR ( a.Blocked <> 0 OR a.SPID IN ( SELECT a.Blocked FROM master.sys.sysprocesses WHERE a.Blocked <> 0 AND a.Blocked <> @@SPID ) ) ) ORDER BY a.SPIDSQL Server 2005 이상 또 다른 버젼(최신)
SELECT a.Session_ID ,a.Blocking_Session_ID ,a.Status ,c.Login_Name ,c.Host_Name ,d.client_net_address ,d.local_tcp_port ,c.last_request_start_time ,DB_NAME(a.Database_ID) AS DBName ,a.Command ,a.Reads ,a.Writes ,a.CPU_Time ,a.Logical_Reads ,c.program_name AS ProgramName ,b.text FROM master.sys.dm_exec_requests AS a WITH(NOLOCK) CROSS APPLY master.sys.dm_exec_sql_text(a.sql_handle) AS b INNER JOIN sys.dm_exec_sessions AS c WITH(NOLOCK) ON a.session_id = c.session_id INNER JOIN sys.dm_exec_connections AS d WITH(NOLOCK) ON a.session_id = d.session_id WHERE a.session_id <> @@SPID ORDER BY a.session_idLock 세션당 걸린 갯수 확인
SELECT request_session_id, COUNT(*) num_locks FROM sys.dm_tran_locks WITH(NOLOCK) GROUP BY request_session_id ORDER BY COUNT(*) desc
'프로그래밍 > MSSQL\스크립트' 카테고리의 다른 글
[MSSQL] 로그인과 유저 간의 연결 수정 (0) | 2012.04.30 |
---|---|
[MSSQL] 특정 계정으로 로그인된 모든 세션 Kill (0) | 2012.04.29 |
[MSSQL] IP String <-> IP Binary (0) | 2012.04.24 |
[MSSQL] DB의 모든 테이블의 Collation 변경 (0) | 2012.04.24 |
[MSSQL] CSV 파일을 임시 테이블에 저장 (0) | 2012.04.24 |