在 SQL Server 2008 中查找有错误的存储过程?

发布于 2024-11-07 03:31:35 字数 85 浏览 0 评论 0原文

我有一个由近 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

谜兔 2024-11-14 03:31:35

看一下名为 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).

enter image description here

enter image description here

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!

厌味 2024-11-14 03:31:35

您可以使用 sys.sql_modules

SELECT
   OBJECT_NAME(object_id)
FROM
   sys.sql_modules
WHERE
   definitiion LIKE '%MyDeletedColumn%'

OBJECT_DEFINITION

INFORMATION_SCHEMA 视图对此不可靠,因为定义分为多个nvarchar(4000) 行。上面的 2 个方法返回 nvarchar(max)

编辑:鉴于 SQL 搜索是免费的,如 marc_s 所注,这将是一个更好的解决方案。

You can use sys.sql_modules

SELECT
   OBJECT_NAME(object_id)
FROM
   sys.sql_modules
WHERE
   definitiion LIKE '%MyDeletedColumn%'

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.

゛清羽墨安 2024-11-14 03:31:35
select object_name(object_id), *
from sys.sql_module
where definition like '%ColName%'
select object_name(object_id), *
from sys.sql_module
where definition like '%ColName%'
南…巷孤猫 2024-11-14 03:31:35

一种可能的方法是在 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文