Syntax check all stored procedures?

前端 未结 9 1981
情话喂你
情话喂你 2020-12-04 22:51

i want to ensure that all stored procedures are still syntactically valid. (This can happen if someone renames/deletes a table/column).

Right now my solution to chec

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 23:05

    You can also do this "in-place" - without getting all the create statements.

    In addition to setting NOEXEC ON, you will also need to set your favorite SHOWPLAN_* ON (I use SHOWPLAN_TEXT). Now you can get rid of your step 2 and just execute each procedure you retrieved in step 1.

    Here is a sample using an individual stored procedure. You can work it into your favorite loop:

    create procedure tests @bob int as 
    select * from missing_table_or_view
    go 
    
    set showplan_text on; 
    go 
    
    set noexec on 
    
    exec tests 
    
    set noexec off
    go 
    set showplan_text off; 
    go 
    drop procedure tests 
    go
    

    The above sample should generate the following output:

    Msg 208, Level 16, State 1, Procedure tests, Line 2
    Invalid object name 'missing_table_or_view'.

提交回复
热议问题