Microsoft SQL Server - 谁创建了存储过程?
有没有一种好方法可以告诉谁在 SQL Server 2005 中创建了存储过程(在 2008 中也适用)? 在 SQL Management Studio 中,我可以在过程上右键单击/属性来获取创建日期/时间,但如何发现创建者?
Is there a good way to tell who created a stored procedure in SQL Server 2005 (that also works in 2008)? In SQL Management Studio I can right mouse/properties on a proc to get the created date/time but how do I discover the creator?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
现在对您来说可能为时已晚,但您可以跟踪 DDL 活动。
我们的管理数据库中有一个表,其中包含放入其中的所有活动。 它使用 2005 年新增的 DDL 触发器。这些脚本在您的管理数据库(对我来说是 SQL_DBA)中创建一个表,在模型数据库上创建一个触发器,在现有数据库上创建触发器。 我还在最后创建了一个 sp_msforeachDB 语句来禁用所有这些语句。
一个警告 - 您的数据库需要处于 90 的兼容模式(在每个数据库的选项中),否则您可能会开始出现错误。 语句的 EXECUTE AS 部分中的帐户也需要访问权限才能插入到您的管理表中。
It may be too late for you now, but you can keep track of DDL activity.
We have a table in our administrative database that gets all the activity put in it. It uses a DDL trigger, new to 2005. These scripts create a table in your admin DB (SQL_DBA for me), create a trigger on the model db, create triggers on existing databases. I also created a sp_msforeachDB statement at the end to disable all of them.
One caveat - your databases need to be in compatibility mode of 90(in options for each db), otherwise you may start getting errors. The account in the EXECUTE AS part of the statement also needs access to insert into your admin table.
如果它不是很久以前创建的,请尝试以下操作:
它选择当前(开箱即用的)默认跟踪。 如果它是最近创建的(并且服务器最近没有重新启动),那么存储过程对象名称和创建它的登录名将在跟踪数据中。
If it was not created too long ago, try this:
It selects the current (out of the box) default trace. If it was created recently (and the server hasn't been restarted recently), then the stored procedure object name and the login name that created it will be in the trace data.
我相信这在 SQL 2005 中不可用。当然,它在 SQL Management Studio 的属性中不可用,在 sys.objects 表或我能看到的任何其他表中也不可用。
I believe this is not available in SQL 2005. Certainly it's not available in the properties in SQL Management Studio, and not available in the sys.objects table or any others I can see.
按照与 Sam 相同的想法,您可以使用 DDL 触发器来捕获所需的信息,然后将该数据发送到 SQL 服务代理队列,该队列可以将其转发到管理数据库(如果需要,可以位于另一台服务器上),这将然后保存所有 DDL 更改。
这将消除权限问题,因为 DDL 触发器会将数据加载到本地数据库的 Service Broker 队列中,并且 SQL 处理将消息移动到其他数据库的操作。
使用此方法需要进行更多设置,但是一旦设置,无论是谁更改了对象,它都会起作用。
Along the same idea as Sam's, you could use a DDL trigger to capture the needed information, then send that data to a SQL Service broker queue, which could forward it to the Admin database (which could be on another server if needed) which would then hold all the DDL changes.
This would remove the permissions issue as the DDL trigger would be loading data into a Service Broker Queue at the local database and SQL handles the moving of the message to the other database.
There would be a bit more setup with this method, but once setup it would work no matter who made the object change.
如何事后(尤其是几年后)获取这条信息很可能是不可能的。
但是,您可以使用 SQL Server Profiler 来跟踪 DDL 操作。 在事件选择中,检查以下事件:
对象/对象:已更改的
对象/对象:已创建的
对象/对象:已删除
还有许多自定义选项:您可以将输出保存到文件或表,还可以根据任何内容进一步过滤输出列等
How to get this piece of info ex post (especially years later) is most likely not possible.
However, you can use SQL Server Profiler to track DDL actions. In Event Selection, check the following events:
Objects / Object: Altered
Objects / Object: Created
Objects / Object: Deleted
There are also lots of customization options: you can save the output to a file or table, filter the output furthermore based on any columns etc. etc.