1 找出效率低的語句html
SELECT
TOP
10
qs.total_worker_time ,qs.total_logical_reads,qs.last_logical_writes, qs.plan_handle, qs.execution_count, (
SELECT
SUBSTRING
(
text
, qs.statement_start_offset
/
2
+
1
, (
CASE
WHEN
qs.statement_end_offset
=
-
1
THEN
LEN
(
CONVERT
(
nvarchar
(
max
),
text
))
*
2
ELSE
qs.statement_end_offset
END
-
qs.statement_start_offset)
/
2
)
FROM
sys.dm_exec_sql_text(sql_handle))
AS
query_text
FROM
sys.dm_exec_query_stats qs
ORDER
BY
total_worker_time
DESC
2 查看這些語句對應的client, hostname,loginname程序員
select
s.
host_name
,s.PROGRAM_NAME,s.login_name, t.
text
From
sys.dm_exec_requests r
cross
apply sys.dm_exec_sql_text(r.sql_handle) t
inner
join
sys.dm_exec_sessions s
on
r.session_id
=
s.session_id
where
t.
text
like
'
%sqlstatement%
'
--
--- place your sql statement here
and
s.session_id
<>
@@SPID
3肯定這些語句隸屬的存儲過程web
經過第一步獲得的plan_handle,代入dm_exec_query_plan,獲得具體的存儲過程的名稱。若是返回空,則說明該語句是ad-hoc或者是prepared或者是在存儲過程內部使用批結字符串弄出來的語句。若是是以上幾種狀況,咱們是沒法定位對象的,只能讓程序員們逐個排查了sql
select
OBJECT_NAME
(objectid)
from
sys.dm_exec_query_plan ( plan_handle )