February 6, 2012 at 9:42 am
We are creating header for each strored procedure with below details..
-- =================================================================================
-- Program Name:
-- Author:
-- Description:
-- InParameter:
-- OutParameter:
-- Created Date:
-- Revision History :
-- Modified Date Modified By version Description
-----------------------------------------------------------------
-- ==================================================================================
Could you please suggest which is the best practice to place header in SP. Whether it should be above the create procedure or inside procedure. I prefer to use the Header preceding Create procedure as the term refer to header and also it gives more readability to the stored procedure when we generate script from SSMS. I would like to get the suggestion before implementing this.
Thanks in advance.
February 6, 2012 at 10:29 am
I don't think there is a "best practice" for where to place your comments. The most important aspect is to be consistent. I tend to prefer them inside the body of the proc, properly indented. This really all comes down to personal preference.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
February 6, 2012 at 10:32 am
like this.
create procedure asdf
(
@Parameter varchar(10)
) as begin
--Comment block goes here.
select 5
end
For me this gives a nice visual separator in a long script to help isolate each sproc. It also allows you to collapse the entire sproc (including comments) in SSMS.
Again is all about what your style is.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
February 6, 2012 at 10:35 am
It is indeed a matter or personal preference, but consider the results of the [text] field when queried directly. I also think this affects the way results are displayed in profiler.
CREATE PROCEDURE dbo.testComment
AS
/*
a bunch of stuff here
like author, dates and modifcation history
*/
BEGIN
SELECT 1
END
GO
/*
a bunch of stuff here
like author, dates and modifcation history
*/
CREATE PROCEDURE dbo.testComment2
AS
BEGIN
SELECT 1
END
GO
SELECT * FROM syscomments WHERE id = OBJECT_ID('testComment')
SELECT * FROM syscomments WHERE id = OBJECT_ID('testComment2')
GO
DROP PROCEDURE testComment
DROP PROCEDURE testComment2
GO
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgFebruary 6, 2012 at 10:39 am
February 6, 2012 at 11:27 am
I'd put them inside the statement too.
I don't remember how to do it, but it's possible to lose comments that are outside the statement (can't remember how that happens for the life of me at the moment).
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
February 6, 2012 at 2:15 pm
And I stick them outside of the proc.
Mostly because I hate 10-15 lines of green stuck between the name of the procedure and the code... some days I'll be looking at code and forget it's a proc because we comment everything and I'll lose the CREATE PROCEDURE stuff at the top.
that and my first exposure to ERP software 14 years ago the ERP authors put their comment header blocks outside of the stored procs. So my style follows their style, after reading several hundred of their procs, I wanted mine to look as neatly formatted as theirs did. 🙂
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply