简体   繁体   English

获取在SQL Server实例/数据库中执行的查询和过程的列表

[英]Get list of queries and procedures executed in SQL Server instance/database

How do I get a list of what is being happening on an SQL Server 2008 instance? 如何获得SQL Server 2008实例上正在发生的事情的列表?

I would like to know which queries and procedures have been executed. 我想知道执行了哪些查询和过程。 A plus would be to know how much time they have spent. 一个加号是会知道他们花了多少时间。

This activity list must be independent from "who" or "what" triggered it. 此活动列表必须独立于“谁”或“什么”触发了它。 It can be from several applications and several users. 它可以来自多个应用程序和多个用户。

Thanks! 谢谢!

I know it is an older post, but I just found it. 我知道这是一个较旧的帖子,但是我才发现它。 If the Audit did what you wanted so far so fine. 到目前为止,如果审计做了您想要的事情,那就好了。 But did you tried the SQL Profiler ? 但是您是否尝试过SQL Profiler Because that is definietly for this reason: checkig exactly what is happening on the SQL Server instance. 因为这绝对是出于这个原因:请检查SQL Server实例上发生的情况。 And you can save the results into a table for further analyzis. 您可以将结果保存到表中以进行进一步分析。 (You can even combine it with a result from the Windows Performance Monitor and then you can check what happened on the server during that time) (您甚至可以将其与Windows Performance Monitor的结果结合起来,然后可以检查在这段时间内服务器上发生了什么)

Option #1 选项1

SELECT ObjectName,       
ObjectID,       
DatabaseName,       
StartTime,       
EventClass,       
EventSubClass,       
ObjectType,       
ServerName,       
LoginName,       
NTUserName,       
ApplicationName  
FROM ::fn_trace_gettable( 'Trace File Path', default )            
where EventClass in (46,47,164) and EventSubclass = 0  and DatabaseID = db_id();

How will you get the Trace file Path? 您将如何获取跟踪文件路径?

SELECT Path FROM sys.traces where is_default = 1 ;

Option #2 选项#2

This approach will tell which column was added, or what command was used to add 这种方法将告诉您添加了哪一列,或者使用了什么命令来添加

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM