October 15, 2010 at 3:09 am
Hello gurus,
I have recently been told that adding PRINT statements in a Stored Procedure helps when debugging. I agree with that.
But are there any backdraws? The webpages that rely on these Stored Procedures, will they suffer from a PRINT statement (no afaik)?
Are there performance issues?
Thanks!
Ray
October 15, 2010 at 4:14 am
you can use them in debugging , but surely you would remove them before putting them in to production ?
October 15, 2010 at 4:44 am
AFAIK there is no issues with leaving print statements in place; I've never seen or heard of an application suffering due to print statements.
even from an application you can read any messages, including print statements and rows affected statements, by adding an event on the SQLConnection object; that's the same way SSMS reads the messages back as well.
I've always left print statements in place when launched into production, as they were there to help confirm the code was doing what it was supposed to do; even code in production gets debugged sometimes.
Lowell
October 15, 2010 at 7:38 am
steveb. (10/15/2010)
you can use them in debugging , but surely you would remove them before putting them in to production ?
Actually, I create all stored procedures like this:
CREATE PROCEDURE dbo.Test (
@Param1...
@Param2...
@Debug tinyint = 0)
Then, inside the procedure, I use the print statements like:
IF @Debug > 0 PRINT 'My message'
IF @Debug > 1 PRINT 'My Level 2 message'
IF @Debug > 5 SELECT data or variables to show what's going on
In production, just never pass anything to the @Debug parameter. Only use that when running from a query window. By using a tinyint, instead of a bit, I can have different levels of debug messages.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
October 15, 2010 at 7:42 am
WayneS (10/15/2010)
steveb. (10/15/2010)
you can use them in debugging , but surely you would remove them before putting them in to production ?Actually, I create all stored procedures like this:
CREATE PROCEDURE dbo.Test (
@Param1...
@Param2...
@Debug tinyint = 0)
Then, inside the procedure, I use the print statements like:
IF @Debug > 0 PRINT 'My message'
IF @Debug > 1 PRINT 'My Level 2 message'
IF @Debug > 5 SELECT data or variables to show what's going on
In production, just never pass anything to the @Debug parameter. Only use that when running from a query window. By using a tinyint, instead of a bit, I can have different levels of debug messages.
That seems like a really good idea , But I guess it depends on the policies where you work. At our place all code (mainly Python, C# and T-SQL) is reviewed before going into production and any 'debug' code is flagged for removal. They apply the same policy regardless of language.
October 18, 2010 at 1:03 am
Thanks to everyone for comments, I've become a wiser man!
Ray
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply