SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Queries, Plans, and Indexes


Queries, Plans, and Indexes

Author
Message
ericzbeard
ericzbeard
SSC Journeyman
SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)

Group: General Forum Members
Points: 93 Visits: 64
Comments posted to this topic are about the item Queries, Plans, and Indexes
Michael Lynn
Michael Lynn
SSC Journeyman
SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)

Group: General Forum Members
Points: 99 Visits: 379
I am getting the following error messages when executing your query.

Msg 102, Level 15, State 1, Line 18
Incorrect syntax near ' '.
Msg 156, Level 15, State 1, Line 26
Incorrect syntax near the keyword 'as'.
Msg 102, Level 15, State 1, Line 31
Incorrect syntax near ' '.
ericzbeard
ericzbeard
SSC Journeyman
SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)

Group: General Forum Members
Points: 93 Visits: 64
Something weird is happening with hidden characters in the site's text box control. I copy-pasted the script and had to delete a bunch of white space to get it to work (even though it looks the same).

Try this version:

/*

This query gets all queries, their query plans, and all indexes included in those plans.


Authors:            Eric Z. Beard, eric@loopfx.com, ericzbeard@yahoo.com
                        (borrowed some stuff from http://mohammedu.spaces.live.com/Blog/cns!6699CF8ADD3D4F67!325.entry,
                            Greg Lindwood? Uma Chandran?)
Date of Origin:        July, 2008

*/

use master;

;with xmlnamespaces('http://schemas.microsoft.com/sqlserver/2004/07/showplan' as s)
select st.text
, qp.query_plan
, qp_objects.qp_obj_schema
, qp_objects.qp_obj_table
, qp_objects.qp_obj_index
from (
select s.sql_handle, s.plan_handle, max(s.execution_count) as ec, max(s.total_logical_reads) as tlr
from sys.dm_exec_query_stats as s
group by s.sql_handle, s.plan_handle
) as qs
cross apply sys.dm_exec_query_plan(qs.plan_handle) as qp
cross apply sys.dm_exec_sql_text(qs.sql_handle) as st
cross apply (select obj_nodes.value('@Schema', 'nvarchar(130)') as qp_obj_schema , obj_nodes.value('@Table', 'nvarchar(130)') as qp_obj_table, obj_nodes.value('@Index', 'nvarchar(130)') as qp_obj_index
from qp.query_plan.nodes('//s:Object[@Schema != "[sys]" and @Index and local-name(parent::node()) != "Update"]') as qry_plan(obj_nodes)
) as qp_objects
;
Michael Lynn
Michael Lynn
SSC Journeyman
SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)SSC Journeyman (99 reputation)

Group: General Forum Members
Points: 99 Visits: 379
That did it. Thanks for the quick response and the fix.
SqlBarbarian
SqlBarbarian
Valued Member
Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)

Group: General Forum Members
Points: 68 Visits: 543
isn't there a way to edit submitted queries? I'm a little confused by my start to using this addin, as not sure if there are "updates". Gist's are version controlled, and not sure if anyway to see this with sql scripts using this tool?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search