Return top 20 queries by Average CPU

Aug 31

I’ve recently used this when troubleshooting some unexplained high CPU load on my server: select top 20 st.objectid, st.dbid, total_worker_time/execution_count AS AverageCPUTime, CASE statement_end_offset WHEN -1 THEN st.text  ELSE SUBSTRING(st.text,statement_start_offset/2,statement_end_offset/2) END AS StatementText from  sys.dm_exec_query_stats qs CROSS...

Read More

How to fix Orphaned Users

Aug 31

 To view if there are any orphaned users, run this query against the DB;  sp_change_users_login ‘report’ To fix;  sp_change_users_login ‘update_one’, ‘dbUser’, ‘sqlLogin’

Read More

Determining the no of processor cores in your SQL Server

Aug 31

SELECT cpu_count/hyperthread_ratio AS cores    FROM sys.dm_os_sys_info;

Read More

Hunting down those expensive SPs

Aug 19

A query to find out which Stored Procedures are taking the longest to run ( in this example – the Top 10). I’m sure there are many other ways but this is a quick and easy script I found. SELECT TOP 10 obj.name, max_logical_reads, max_elapsed_time FROM sys.dm_exec_query_stats A CROSS APPLY sys.dm_exec_sql_text(sql_handle) H INNER JOIN sys.sysobjects...

Read More

Undocumented Stored Procedures

Aug 19

Just a quick list of undocumented SPs, many of which are deprecated. Note, use caution using some of these ! But others are very useful (e.g....

Read More