views:

51

answers:

1

I was reading this fabulous list of sql dba scripts at http://www.sqldbtools.com/Scripts.aspx, not affiliated with them. And I want to run this query...

select top 10
    qs.execution_count,
    st.dbid,
    DB_NAME(st.dbid) as DbName,
    st.text from sys.dm_exec_query_stats as qs cross
apply sys.dm_exec_sql_text(sql_handle)
st order by execution_count desc

But for our production server, it is way too risky, to change compatibility modes, is there a script i can use that doesn't require that?

+3  A: 

Your query will work on SQL Server 2005, as long as you don't run it in context of the database with the lower compat level

USE master
GO
select top 10
    qs.execution_count, st.dbid, DB_NAME(st.dbid) as DbName, st.text
from 
    sys.dm_exec_query_stats as qs
    cross apply
    sys.dm_exec_sql_text(sql_handle) st order by execution_count desc

From Paul Randall's Misconceptions about running DMVs on databases with lower compatibility levels

gbn
But it's the lower compat level that i need the data on what the slowest queries are of...I can run it on our development server. But I didn't want to take any risks with server stability by changing compat level on production.
crosenblum
You don't need to change compat level...
gbn