See list of all SQL Queries run on server

会有一股神秘感。 提交于 2019-12-12 12:20:59

问题


Is there a query I can run which will display all the queries which have been run on the server within a date range for a specific database?

I need to find out what parameter values were passed to a Stored Procedure which was executed last week


回答1:


No

The only way this can be done is if a monitoring process is set up in advance.

Monitoring a database, e.g. through SQL Profiler, has a performance impact, so one should be wary about using this against a live system for prolonged periods.

A better way to monitor this kind of activity, would be by use of logging from the calling code.




回答2:


try the below:

SELECT deqs.last_execution_time AS [Time], dest.TEXT AS [Query]
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
ORDER BY deqs.last_execution_time DESC

http://blog.sqlauthority.com/2008/01/03/sql-server-2005-last-ran-query-recently-ran-query/



来源:https://stackoverflow.com/questions/6842862/see-list-of-all-sql-queries-run-on-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!