Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable PRINT in SQL Server

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 SET NOCOUNT ON, but for user messages.

like image 532
Lukasz Lysik Avatar asked Jul 09 '10 12:07

Lukasz Lysik


People also ask

How to disable from printing report?

Select Services. Select Printing. Select General. Remove the check mark from the Print at Power On check box under the Configuration Report option.

Why set Nocount on is used in SQL?

When you use SET NOCOUNT ON, the message that indicates the number of rows that are affected by the T-SQL statement is not returned as part of the results. When you use SET NOCOUNT OFF; the count is returned. Using SET NOCOUNT ON can improve performance because network traffic can be reduced.

Are there print statements in SQL?

The SQL PRINT statement serves to display the user-defined message. For example, you are developing a script with T-SQL Loops, and you want to display some specific message on each iteration of a loop. Then you can use the PRINT statement. Or, you can use it when developing a script with conditional statements.


1 Answers

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.

like image 62
Daniel P Avatar answered Oct 06 '22 19:10

Daniel P