Syntax check all stored procedures?

前端 未结 9 1976
情话喂你
情话喂你 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:18

    If you are using sql 2008 r2 or below then do not use

    SET NOEXEC ON

    It only checks the syntax and not for potential errors like the existence of tables or columns. Instead use:

    SET FMTONLY ON

    it will do a full compile as it tries to return the meta data of the stored procedure.

    For 2012 and you will need to use stored procedure: sp_describe_first_result_set

    Also you can do a complete script in Tsql that checks all sp and views, its just a bit of work.

    UPDATE I wrote a complete solution for in tsql that goes through all user defined stored proceedures and checks there syntax. the script is long winded but can be found here http://chocosmith.wordpress.com/2012/12/07/tsql-recompile-all-views-and-stored-proceedures-and-check-for-error/

提交回复
热议问题