sqlservers 慢查询函数
2021/11/19 19:15:32
本文主要是介绍sqlservers 慢查询函数,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1、
SELECT spid, blocked, DB_NAME(sp.dbid) AS DBName, program_name, waitresource, lastwaittype, sp.loginame, sp.hostname, a.[Text] AS [TextData], SUBSTRING ( A.text, sp.stmt_start / 2, ( CASE WHEN sp.stmt_end = - 1 THEN DATALENGTH( A.text ) ELSE sp.stmt_end END - sp.stmt_start ) ) AS [current_cmd],* FROM MASTER.dbo.sysprocesses AS sp OUTER APPLY sys.dm_exec_sql_text ( sp.sql_handle ) AS A
2、
SELECT SPID=p.spid, DBName = convert(CHAR(20),d.name), ProgramName = program_name, LoginName = convert(CHAR(20),l.name), HostName = convert(CHAR(20),hostname), Status = p.status, BlockedBy = p.blocked, LoginTime = login_time, QUERY = CAST(TEXT AS VARCHAR(MAX)) FROM MASTER.dbo.sysprocesses p INNER JOIN MASTER.dbo.sysdatabases d ON p.dbid = d.dbid INNER JOIN MASTER.dbo.syslogins l ON p.sid = l.sid CROSS APPLY sys.dm_exec_sql_text(sql_handle)
3、
SELECT TOP 100 ( total_elapsed_time / execution_count ) / 1000000 N'平均时间s', total_elapsed_time / 1000000 N'总花费时间s', total_worker_time / 1000000 N'所用的CPU总时间s', total_physical_reads N'物理读取总次数', total_logical_reads / execution_count N'每次逻辑读次数', total_logical_reads N'逻辑读取总次数', total_logical_writes N'逻辑写入总次数', execution_count N'执行次数', qs.statement_start_offset, st.text, statement_end_offset, SUBSTRING ( st.text, ( qs.statement_start_offset/ 2 ) + 1, ( ( CASE statement_end_offset WHEN - 1 THEN DATALENGTH( st.text ) ELSE qs.statement_end_offset END - qs.statement_start_offset ) / 2 ) + 1 ) N'执行语句', creation_time N'语句编译时间', last_execution_time N'上次执行时间' FROM sys.dm_exec_query_stats AS qs CROSS APPLY sys.dm_exec_sql_text ( qs.sql_handle ) st ORDER BY total_elapsed_time / execution_count DESC;
这篇关于sqlservers 慢查询函数的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-08Docker下的SqlServer发布订阅启用
- 2023-06-05Docker安装MS SQL Server并使用Navicat远程连接
- 2023-05-25深入浅出 SQL Server CDC 数据同步
- 2023-05-12通过空间占用和执行计划了解SQL Server的行存储索引
- 2023-04-24以SQLserver为例的Dapper详细讲解
- 2022-11-30SQL server高级函数查询
- 2022-11-26SQL SERVER数据库服务器CPU不能全部利用原因分析
- 2022-11-21SQL Server 时间算差值/常用函数
- 2022-11-20调试Archery连接SQL Server提示驱动错误
- 2022-10-22SQL Server 完整、差异备份+完整、差异还原(详细讲解,规避错误)