Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

3 Answers 3

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. http://msdn.microsoft.com/en-us/library/ms189799.aspx

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

 
discard

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.