My basic script to find the most expensive queries running on SQL Server using DMVs, the one I use in my query tuning consulting projects.
SQL SERVER – Get Latest SQL Query for Sessions – DMV
Want the latest SQL query for sessions on your server? Join sys.dm_exec_connections with sys.dm_exec_sql_text using most_recent_sql_handle.
SQL SERVER – Find Max Worker Count using DMV – 32 Bit and 64 Bit
Does doubling the CPUs double the worker threads? No. Use sys.dm_os_sys_info to find Max Worker Count, and see the formula for 32 bit and 64 bit.
SQL SERVER – DMV Error: FIX: Error: Msg 297, Level 16 The user does not have permission to perform this action
Msg 297 appears when a user runs a DMV without the right permission. Ask your admin to GRANT VIEW SERVER STATE, and the DMV runs without errors.
SQL SERVER – Recently Executed T-SQL Query
fn_get_sql() and DBCC INPUTBUFFER will be deprecated. Use sys.dm_exec_query_stats and sys.dm_exec_sql_text to see each recently executed T-SQL query.
SQL SERVER – Measure CPU Pressure – Detect CPU Pressure
How to measure CPU pressure in SQL Server and tell whether your server needs a faster CPU or more CPUs, using simple scripts and signs.
SQL SERVER – Interesting Observation of DMV of Active Transactions and DMV of Current Transactions
sys.dm_tran_active_transactions and sys.dm_tran_current_transaction look alike, but one lists active transactions for the instance, the other only your session.





