如何查找数据库中使用 UNION 的所有对象
如何找到包含 UNION 关键字的所有视图和 SP?
(另一个问题:SP和视图的文本存储在哪个系统表中)
谢谢
How can I find all views and SP's that contains UNION keyword?
(Alternate question: in what system table is stored the text of SP's and Views)
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个有点幼稚但可行的示例:(在 SQL Server 2005 和 2008 R2 上测试)
要巩固它,只需通过 object_id 链接进行连接,并按对象类型过滤视图和存储过程,而不是使用 LIKE。
更简单:
警告:由于我们正在对每个对象的创建脚本执行 LIKE 比较,因此如果/当它出现在注释中时,我们还将选择 UNION 一词。这对您来说可能没问题,但如果您需要结果更具确定性并避免这种情况,您的 WHERE 子句将需要更复杂,可能使用正则表达式来优化结果。
Here is a somewhat naive but workable example: (tested on SQL Server 2005 & 2008 R2)
To solidify it just join via the object_id link and filter for views and stored procs by object type rather than using LIKE.
Simpler:
Caveat: Since we're performing a LIKE comparison against the create script of each object we will also pick up on the word UNION if/when it appears in comments. That might be OK for you but if you need to results to be more deterministic and avoid such cases your WHERE clause will need to be more complex, possibly using regex to refine the results.
就我个人而言,我喜欢使用
INFORMATION_SCHEMA
视图:对于存储过程:
对于视图:
这些视图仅限于您当前
使用
的数据库中的定义。或者,xSQL 软件中的一个出色工具可为您提供强大的 Microsoft SQL 搜索功能Server 2005 和 2008。
更新:正如 @Bogdan 指出的,
INFORMATION_SCHEMA
定义仅限于前 4000 个 人物。我已经更新了我的答案以包含解决方法。此时,跟踪sys
视图可能会更容易。Personally I like using the
INFORMATION_SCHEMA
views:For stored procedures:
And for views:
These views are limited to definitions in whichever database you're currently
USE
ing.Alternatively, there is a wonderful tool from xSQL software that gives you powerful searching capabilities for Microsoft SQL Server 2005 and 2008.
UPDATE: As @Bogdan pointed out, the
INFORMATION_SCHEMA
definitions are limited to the first 4000 characters. I've updated my answer to include a workaround. At this point it may just be easier to go after thesys
views.这些东西存储在 sys.sql_modules 中。
Those things are stored in
sys.sql_modules
.