在 SQL Server 2008 中查找有错误的存储过程?
我有一个由近 200 个表和 3000 个存储过程组成的数据库。
我已经从一些表中删除了一些字段,现在如何找到引用这些已删除字段的存储过程?
I have a database which consists of almost 200 tables and 3000 stored procedures.
I have deleted some fields from some tables, how can I now find stored procedures in which those deleted fields are referred?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看一下名为 SQL 搜索 执行此操作 - 它在整个数据库中搜索任何类型的字符串。
对于任何 DBA 或数据库开发人员来说,它都是一个很棒的必备工具 - 我是否已经提到过它绝对免费可用于任何类型的用途?
因此,在您的情况下,您可以输入您删除的列名称,然后选择仅搜索您的存储过程 - 在大约一秒钟内,您将获得包含该特定列名称的所有存储过程的列表。绝对很棒的东西!
Have a look at the FREE Red-Gate tool called SQL Search which does this - it searches your entire database for any kind of string(s).
It's a great must-have tool for any DBA or database developer - did I already mention it's absolutely FREE to use for any kind of use??
So in your case, you could type in the column name you deleted, and select to search only your stored procedures - and within a second or so, you'll have a list of all stored procs that contain that particular column name. Absolutely great stuff!
您可以使用 sys.sql_modules
或 OBJECT_DEFINITION
INFORMATION_SCHEMA 视图对此不可靠,因为定义分为多个nvarchar(4000) 行。上面的 2 个方法返回 nvarchar(max)
编辑:鉴于 SQL 搜索是免费的,如 marc_s 所注,这将是一个更好的解决方案。
You can use sys.sql_modules
Or OBJECT_DEFINITION
The INFORMATION_SCHEMA views are unreliable for this because the definition is split over several nvarchar(4000) rows. The 2 methods above return nvarchar(max)
Edit: Given SQL Search is free as note by marc_s, this will a better solution.
一种可能的方法是在
SET SHOWPLAN_XML ON
处于活动状态时使用虚拟参数调用每个存储过程。这不会运行该过程,但会生成计划的 .xml 表示形式 - 如果引用的列丢失,则会失败。但是,如果您使用#temp 表,无论如何这都会失败。 :(您很可能希望自动化此过程,而不是编写 3000 个过程调用。
免责声明:这不是一种拾取丢失列的万无一失的方法,但祝您好运,找到更好的东西!
One possible approach is to call each stored procedure with dummy parameters with
SET SHOWPLAN_XML ON
active. This won't run the procedure, but will generate an .xml representation of the plan - and will fail if referenced columns are missing. If you make use of #temp tables, however, this'll fail regardless. :(You'd most likely want to automate this process, rather than writing out 3000 procedure calls.
DISCLAIMER: This isn't a bulletproof approach to picking up on missing columns, but good luck finding anything better!