开发者

Is there any way to know every sentence executed in SQL Server 2005?

I need to know if there is any way to know every sentence executed in a SQL Server 2005 database. That is because I have a registry modified in a concrete date, and I would like t开发者_高级运维o know the sentence executed to update the registry. Of course, if I could have more information besides the sentence, it would be great!

Thank you very much!


If your statement has been executed in the very recent past, this query will get you the last few executed statements and may be of use.

SELECT 
    DB_NAME (dest.dbid) DatabaseName, 
    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

If you know when the statement gets executed, and want to capture all SQL statements at the time, then you can use the Profiler to Trace all activity.

http://msdn.microsoft.com/en-us/library/ms187929%28v=SQL.90%29.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜