SQL日常维护的语句
1、查詢當前正在執行的語句:
SELECT??
der.[session_id],der.[blocking_session_id],??
sp.lastwaittype,sp.hostname,sp.program_name,sp.loginame,??
der.[start_time] AS '開始時間',??
der.[status] AS '狀態',??
dest.[text] AS 'sql語句',??
DB_NAME(der.[database_id]) AS '數據庫名',??
der.[wait_type] AS '等待資源類型',??
der.[wait_time] AS '等待時間',??
der.[wait_resource] AS '等待的資源',??
der.[logical_reads] AS '邏輯讀次數'??
FROM sys.[dm_exec_requests] AS der??
INNER JOIN master.dbo.sysprocesses AS sp ON der.session_id=sp.spid??
CROSS APPLY? sys.[dm_exec_sql_text](der.[sql_handle]) AS dest??
--WHERE [session_id]>50 AND session_id<>@@SPID??
ORDER BY der.[session_id]??
GO
2、是否堵塞:
SELECT spid, blocked, waittime, waittype, waitresource
, p.dbid, cpu, physical_io, memusage, open_tran AS status
, login_time, last_batch, hostname, program_name, hostprocess
, loginame, cmd, text
FROM master.dbo.sysprocesses p
CROSS APPLY sys.dm_exec_sql_text(p.sql_handle) s
WHERE blocked > 0
OR spid IN (
SELECT blocked
FROM master.dbo.sysprocesses
WHERE blocked > 0
)
GO
3、是否有未提交事物:
SELECT spid, blocked, waittime, waittype, waitresource
, p.dbid, cpu, physical_io, memusage, open_tran
, status, login_time, last_batch, hostname, program_name
, hostprocess, loginame, cmd, text
FROM master.dbo.sysprocesses p
CROSS APPLY sys.dm_exec_sql_text(p.sql_handle) s
WHERE open_tran <> 0
GO
4、?死鎖:?
--drop table #deadlock
CREATE TABLE #deadlock(LogDate DATETIME,ProcessInfo VARCHAR(20),Text VARCHAR(2000))??
go??
INSERT INTO #deadlock EXEC xp_readerrorlog 0,1,'deadlock victim',NULL,'2016-07-20 14:00:00','2016-07-30','DESC'? ??
go
總結
以上是生活随笔為你收集整理的SQL日常维护的语句的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: @keyframes中translate
- 下一篇: 虚化4独立游戏开发第一章:策划案