Store procedure header

  • 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.

  • 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/

  • 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/

  • 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. Selburg
  • Including them inside the SQL statement

    -- + 1

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • 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

  • 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. 🙂



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply