Can we view logs of all queries in SQL Server like MySQL general query logs?
How can this be achieved?
Asked
Active
Viewed 5,666 times
2

Super Kai - Kazuya Ito
- 22,221
- 10
- 124
- 129

Atul Mishra
- 298
- 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
-
1Possible 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
2 Answers
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
- 17,041
- 6
- 41
- 60
0
The SQL query below can show simple transaction query logs:
SELECT Operation, [Begin Time], [End Time]
FROM fn_dblog(NULL,NULL)
This is how it looks like below:

Super Kai - Kazuya Ito
- 22,221
- 10
- 124
- 129