如何获取 SQL Server 中触发器的定义(主体)?
由于无法找到满足我需求的 SQL diff 工具,我正在编写自己的工具。 在 INFORMATION_SCHEMA 和 sys 表之间,我有一个基本完整的工作版本。 但我在元数据中找不到的一件事是触发器的定义,即实际的 SQL 代码。 我是否忽略了什么?
谢谢。
谢谢,皮特,我不知道!
斯科特,我正在使用非常基本的托管包,不允许远程连接到数据库。 我不知道 RedGate 的规格(反正我买不起)他们是否提供了解决方法,尽管也有 API(例如来自 Apex 的 API),但我没有看到我认为投资一个解决方案仍然需要更多的编程。 :)
我的解决方案是在网站上放置一个 ASPX 页面,充当一种“架构服务”,以 XML 形式返回收集的元数据。 我设置了一个小型 AJAX 应用程序,它将任意数量的目录实例与主实例进行比较并显示差异。 这并不完美,但对我来说是向前迈出的重要一步。
再次感谢!
Unable to find a SQL diff tool that meets my needs, I am writing my own. Between the INFORMATION_SCHEMA and sys tables, I have a mostly-complete working version. But one thing I can't find in the metadata is the definition of a trigger, you know, the actual SQL code. Am I overlooking something?
Thanks.
Thanks, Pete, I didn't know about that!
Scott, I'm working with very basic hosting packages that don't allow remote connections to the DB. I don't know from the specs on RedGate (which I can't afford anyway) whether they provide a workaround for that, and although there are also API's out there (such as the one from Apex), I didn't see the point in investing in a solution that was still going to require more programming on my part. :)
My solution is to drop an ASPX page on the site that acts as a kind of "schema service", returning the collected metadata as XML. I set up a little AJAX app that compares any number of catalog instances to a master and shows the diffs. It's not perfect, but a major step forward for me.
Thanks again!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
该查询返回触发器及其名称和正文。
this query return trigger with its name and body.
您可以通过多种方式查看 SQL Server 触发器定义。
从系统视图查询:
或
使用OBJECT_DEFINITION函数定义:
使用sp_helptext存储过程定义:
you have various ways to view SQL Server trigger definition.
querying from a system view:
Or
definition using OBJECT_DEFINITION function:
definition using sp_helptext stored procedure:
为了扩展 SQLMenace 的答案,这里有一个简单的查询,用于从数据库返回所有触发器及其定义:
To expand on SQLMenace's answer, here's a simple query to return all triggers and their definitions from a database:
sp_helptext 用于获取构成触发器的 sql。
syscomments 视图中的文本列还包含用于创建对象的 sql。
sp_helptext works to get the sql that makes up a trigger.
The text column in the syscomments view also contains the sql used for object creation.
对于 2005 和 2008,您可以使用 OBJECT_DEFINITION() 函数
For 2005 and 2008 you can use the OBJECT_DEFINITION() function