views:

36

answers:

2

Is there a way to capture STATISTICS IO and TIME within T-SQL for logging.

+1  A: 

No, not using SET STATISTICS IO ON.

But then you don't need to; run SQL Profiler and start a trace to output to a file. Include Reads and Duration.

Mitch Wheat
+2  A: 

Sort of. The same statistics as those given by SET STATISTICS TIME are captured by the query statistics DMVs like sys.dm_exec_query_stats. The DMVs are queryable from T-SQL. The SET STATISTICS IO are only captured as an aggregate value (last_logical_reads, last_physical_read) per execution without the differentiation per-rowset given by SET STATISTICS IO. Overal though the DMV can serve the same purpose as SET STATISTICS IO.

Remus Rusanu
Thanks a lot.. thats is exactly what I wanted..
TonyP