Disable PRINT in SQL Server

前端 未结 4 1719
抹茶落季
抹茶落季 2021-01-13 02:08

I have a script with many debug messages, which are printed by PRINT function. Is there any way to disable that messages? I have in mind something like SE

4条回答
  •  清歌不尽
    2021-01-13 02:28

    I like to set a variable, @Debug tinyint in my scripts/SPs.

    Default/set this to 0 to suppress messages, 1 to show messages.

    Then instead of using PRINT, use:

    IF @Debug > 0 RAISERROR( 'Busy doing something...', 0, 1 ) WITH NOWAIT
    

    Using WITH NOWAIT forces the message to be displayed immediately and not just when the output buffer is flushed.

    As a convention, I use @Debug = 1 for progress messages, @Debug = 2 to include dynmaic SQL, @Debug = 3 to output result sets.

    Of course if you have GO batch terminators in your script the variable method won't work.

提交回复
热议问题