Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to use SQL 2005 Server profiler to run a trace for queries that happened for example 6 hours ago? Or is trace only used for real time? I'm trying to find a way to view old TSQL queries. Is this possible with SQL 2005?

share|improve this question

Simple question, simple answer: No. This is realtime.

share|improve this answer

Trace is real time only, although if you want to do some auditing on your database in the future, you might want to set up triggers.

share|improve this answer

Profiler captures realtime events, so past events are gone.

You can have some past informations looking into the procedure cache, but this isn't the complete log of queries:

SELECT [cp].[refcounts] 
, [cp].[usecounts] 
, [cp].[objtype] 
, [st].[dbid] 
, [st].[objectid] 
, [st].[text] 
, [qp].[query_plan] 
FROM sys.dm_exec_cached_plans cp 
CROSS APPLY sys.dm_exec_sql_text ( cp.plan_handle ) st 
CROSS APPLY sys.dm_exec_query_plan ( cp.plan_handle ) qp ;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.