Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
raaj
Posting Yak Master
129 Posts |
Posted - 2014-03-26 : 23:48:07
|
Hello,Is it possible to know what SQL queries ran on a particular date (eg say 01/02/2014) on a database?Any ideas?Thanks,Raaj. |
|
denis_the_thief
Aged Yak Warrior
596 Posts |
Posted - 2014-03-31 : 16:27:16
|
No really.I have a query below. It can give some insight. But it only gives you the 1st run and most recent run, so if your query was run more then twice, you are just guessing. Also this only goes back so far. But worth a try:SELECT TOP 5000 a.Last_Execution_Time, cast(last_elapsed_time/1000000.0 as decimal(10, 3)) Last_Elapsed_Seconds, cast(max_elapsed_time/1000000.0 as decimal(10, 3)) Max_Elapsed_Seconds, cast(total_elapsed_time/1000000.0/Execution_count as decimal(10, 3)) Avg_Seconds, Execution_Count, db_name(dbID) Database_Name, object_name(ObjectID, dbID) Object_Name, SUBSTRING(b.text, (a.statement_start_offset/2) + 1, ((CASE statement_end_offset WHEN -1 THEN DATALENGTH(b.text) ELSE a.statement_end_offset END - a.statement_start_offset)/2) + 1) AS statement_text, total_worker_time as CPU_time, a.* FROM sys.dm_exec_query_stats a CROSS APPLY sys.dm_exec_sql_text (a.sql_handle) AS b where db_name(dbID) = ['Your Database Name']ORDER BY 1 |
|
|
|
|
|
|
|