大佬教程收集整理的这篇文章主要介绍了【SqlServer】 分享 几个 优化 Sql 的 语句,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
1、查找目前sql Server所执行的sql语法,并展示资源情况:
SELECT
s2.dbid ,
statement_end_offset
[语句] ,
[执行次数] ,
[上次开始执行计划的时间] ,
[自编译以来执行所用的 cpu 时间总量(微秒)] ,
[上次执行计划所用的 cpu 时间(微秒)] ,
[单次执行期间曾占用的最小 cpu 时间(微秒)] ,
[单次执行期间曾占用的最大 cpu 时间(微秒)] ,
[总逻辑读] ,
[上次逻辑读] ,
[最少逻辑读] ,
[最大逻辑读] ,
[总逻辑写] ,
[上次逻辑写] ,
[最小逻辑写] ,
[最大逻辑写]
BY
DESC
2、展示耗时查询:
-- List expensive queries
@minEXECUTIONS = 5
As
ExeCnt
as
AvgcpuTimeMiS
name
Databasename
(EST.text
- EQs.statement_start_offset) / 2
-- Optional with Query plan; remove comment to show, but then the query takes !!much longer time!!
EQS
EQs.execution_count > @minEXECUTIONS
-- Current processes and their sql statements
LoginName
Processstatus
Command
LastBatch
cpu
PhysicalIo
[RowCount]
sqlStatement
PRO
INNER
DB
SES
PRO.spid = SEs.session_id
-- Exclude system processes
DESC
;
4、存储过程执行情况:
SELECT
ISNULL
(DBs.
name
''
Databasename
ObjectName
CachedTime
Lastelapsedtime
ExecutionCount
AvgWorkerTime
Avgelapsedtime
EPS
/*
开销较大的查询
(s.execution_count) SUM_Execution_count ,monospace!important; font-size:1em!important; padding:0px!important; color:black!important; BACkground:none!important; margin:0px!important; border:0px!important; outline:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; min-height:auto!important'>(s.@R_203_10586@l_elapsed_timE) SUM_@R_203_10586@l_elapsed_time ,monospace!important; font-size:1em!important; padding:0px!important; color:black!important; BACkground:none!important; margin:0px!important; border:0px!important; outline:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; min-height:auto!important'>(s.@R_203_10586@l_worker_timE) SUM_@R_203_10586@l_worker_time ,monospace!important; font-size:1em!important; padding:0px!important; color:black!important; BACkground:none!important; margin:0px!important; border:0px!important; outline:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; min-height:auto!important'>(s.@R_203_10586@l_logical_reads) SUM_@R_203_10586@l_logical_reads ,monospace!important; font-size:1em!important; padding:0px!important; color:black!important; BACkground:none!important; margin:0px!important; border:0px!important; outline:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; min-height:auto!important'>(s.@R_203_10586@l_logical_writes) SUM_@R_203_10586@l_logical_writes
BY
s.plan_handle
DESC
以上是大佬教程为你收集整理的【SqlServer】 分享 几个 优化 Sql 的 语句全部内容,希望文章能够帮你解决【SqlServer】 分享 几个 优化 Sql 的 语句所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。