Is there a way to have SQL server validate object references in Stored Procs?

后端 未结 7 2136
半阙折子戏
半阙折子戏 2021-01-13 20:12

The following code executes fine in SQL Server

create proc IamBrokenAndDontKnowIt as
select * from tablewhichdoesnotexist

Of course if I tr

7条回答
  •  死守一世寂寞
    2021-01-13 21:04

    You can use

    SET FMTONLY ON
    EXEC dbo.My_Proc
    SET FMTONLY OFF
    

    You'll need to capture the error(s) somehow, but it shouldn't take much to put together a quick utility application that takes advantage of this for finding invalid stored procedures.

    I haven't used this extensively, so I don't know if there are any side-effects to look out for.

提交回复
热议问题