2

Can we view logs of all queries in SQL Server like MySQL general query logs?
How this can be achieved ?

shA.t
  • 15,880
  • 5
  • 49
  • 104
Atul Mishra
  • 280
  • 2
  • 11
  • Yes.. Similar functionality comes with Sql Profiler https://msdn.microsoft.com/en-us/library/ms181091.aspx – Shakeer Mirza Jan 05 '17 at 12:45
  • 1
    Possible duplicate of [How to see query history in SQL Server Management Studio](http://stackoverflow.com/questions/5299669/how-to-see-query-history-in-sql-server-management-studio) – d_luffy_de Jan 05 '17 at 12:50

1 Answers1

1

Yes. You can try a query like below

SELECT  *
    --use only text to see relevant query information
FROM    
  sys.dm_exec_query_stats stats
CROSS APPLY 
  sys.dm_exec_sql_text(stats.sql_handle) 
 -- Note that this is a function which takes in sql_handle as parameter

EDIT: You can see a similar question on DBA SO site https://dba.stackexchange.com/questions/4043/can-i-see-historical-queries-run-on-a-sql-server-database

Community
  • 1
  • 1
DhruvJoshi
  • 16,585
  • 6
  • 37
  • 57