开发者

Finding stored procedures with errors in SQL Server 2008?

I have a database which consists of almost 200 tables and 3000 stored procedures.

I have deleted some fields from some t开发者_高级运维ables, how can I now find stored procedures in which those deleted fields are referred?


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).

Finding stored procedures with errors in SQL Server 2008?

Finding stored procedures with errors in SQL Server 2008?

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!


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.


select object_name(object_id), *
from sys.sql_module
where definition like '%ColName%'


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜