Getting the current connections to a SQL Server
1 2 |
SELECT * FROM sys.dm_exec_connections |
Views – 1974
Read MoreAll things SQL Server
1 2 |
SELECT * FROM sys.dm_exec_connections |
Views – 1974
Read MoreThis will also display the SQL Statement that is the offending blocker. Online index operations: Online index operations were added as an availability…
Read MoreTop 10 SQL Scripts You Should Know Views – 1793
Read MoreUsers frequently want spreadsheets with embedded links to web pages, one per row. This is one way to get them.
1 2 |
SELECT '=HYPERLINK("http://website/somepage.aspx?id=' + CAST(Myid AS VARCHAR) + '", "' + CAST(Myid AS VARCHAR) + '")' AS linkToItem FROM MyTable |
Views –…
Read MoreUsing SQL Profiler to trace a Stored Procedure call Views – 1799
Read MoreYou can use this T-SQL to get the plan handle for a sproc that has a bad execution plan:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
SELECT OBJECT_NAME(st.objectid,st.dbid) AS ObjectName, cp.usecounts AS ExecutionCount, cp.cacheobjtype AS ObjectType, cp.plan_handle AS PlanHandle, deps.cached_time as CachedDate, deps.last_execution_time AS LastExecuted, deps.total_worker_time AS TotalWorkerTime, st.TEXT AS QueryText, qp.query_plan AS QueryPlan, GETDATE() AS TimeQueryExecuted FROM sys.dm_exec_cached_plans AS cp CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) AS qp CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) AS st INNER JOIN sys.dm_exec_procedure_stats deps ON deps.plan_handle = cp.plan_handle WHERE cp.objtype = 'Proc' AND OBJECT_NAME(st.objectid,st.dbid) = 'usp_SomeSproceName'; |
Make sure, to…
Read More
1 2 3 4 5 6 7 8 9 10 11 12 |
SELECT OBJECT_NAME(st.objectid,st.dbid) AS ObjectName, cp.usecounts AS ExecutionCount, st.TEXT AS QueryText, qp.query_plan AS QueryPlan FROM sys.dm_exec_cached_plans AS cp CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) AS qp CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) AS st WHERE cp.objtype = 'Proc' AND OBJECT_NAME(st.objectid,st.dbid) = 'YourStoredProcedure'; |
Views – 2158
Read MoreSetting ANSI_NULLS ON will make make the Sprocs run fast. See this article: Query is fast but Sproc is slow Views – 1754
Read MoreHere is a great article on trouble-shooting T-SQL query slowness: Trouble-shooting SQL Server Slowness Views – 1758
Read MoreUpdates query optimization statistics on a table or indexed view. By default, the query optimizer already updates statistics as necessary to improve the…
Read More