October 23, 2013 at 4:09 pm
Hi,
I need to get all queries that executed from last 4 hours. How can I get that?
Thanks!
October 23, 2013 at 4:38 pm
Something like this?
SELECT t.text, q.last_execution_time
FROM sys.dm_exec_query_stats q
CROSS APPLY sys.dm_exec_sql_text(sql_handle ) t
WHERE last_execution_time >= DATEADD(HH, -4, GETDATE())
October 24, 2013 at 4:51 am
Luis's suggestion is quite good, but please keep in mind that you won't get the exact sequence of the statements that way.
For instance, you won't get parameteres for parameterized queries.
If you need to extract the exact workload in the last four hours, a trace is the way to go (especially if you're planning to replay it).
Another option is capturing the activity with an Extended Events session (less impact on the server, but more difficult to replay).
-- Gianluca Sartori
October 24, 2013 at 8:26 am
spaghettidba (10/24/2013)
Luis's suggestion is quite good, but please keep in mind that you won't get the exact sequence of the statements that way.For instance, you won't get parameteres for parameterized queries.
If you need to extract the exact workload in the last four hours, a trace is the way to go (especially if you're planning to replay it).
Another option is capturing the activity with an Extended Events session (less impact on the server, but more difficult to replay).
+1
I was getting out of the office and didn't advice on the downsides of my solution. A trace has certainly helped me in the past.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply