select * from master.sys.dm_os_performance_counterswhere counter_name='Batch Requests/sec'
declare @v1 bigint, @v2 bigintselect @v1 = cntr_value from master.sys.dm_os_performance_counterswhere counter_name='Batch Requests/sec'waitfor delay '00:00:01'select @v2 = cntr_value from master.sys.dm_os_performance_counterswhere counter_name='Batch Requests/sec'select @v2 - @v1
select t1.cntr_value As [Batch Requests/sec], t2.cntr_value As [SQL Compilations/sec], plan_reuse = convert(decimal(15,2), (t1.cntr_value*1.0-t2.cntr_value*1.0)/t1.cntr_value*100)from master.sys.dm_os_performance_counters t1, master.sys.dm_os_performance_counters t2where t1.counter_name='Batch Requests/sec' and t2.counter_name='SQL Compilations/sec'
select * from sys.dm_os_performance_counters where counter_name like '%cache hit ratio%'and object_name like '%plan cache%' and instance_name like '%SQL%'
declare @cachehitratio decimal(18,2)declare @cachehitratiobase decimal(18,2)declare @ratio decimal(18,2)select @cachehitratio = cntr_value from sys.dm_os_performance_counters where object_name = 'SQLServer:Plan Cache'and counter_name = 'Cache Hit Ratio'and instance_name = 'SQL Plans'select @cachehitratiobase = cntr_value from sys.dm_os_performance_counters where object_name = 'SQLServer:Plan Cache'and counter_name = 'Cache Hit Ratio Base'and instance_name = 'SQL Plans'select @ratio = (@cachehitratio/@cachehitratiobase)*100 print @cachehitratioprint @cachehitratiobaseprint @ratio