Sample SQL Comment Headers

It would be easy to see what the request headers look like for users, stored procedures / functions, etc. (so post your examples) ... I really saw what SQL Server Management Studio creates, but I wonder what other people look like ... formatting, characters used, procedure information / details, etc. I think it really makes them different ...

SQL Server Management Studio (version 9) default stored procedure comment header:

-- ============================================= -- Author: Name -- Create date: -- Description: -- ============================================= 
+60
comments sql
Jul 06 '09 at 6:28
source share
13 answers

May I indicate that all these fields “change history” and “changed date” can and should be obtained from your version control software, and not be embedded in the code by the programmer. This is a lesson that C (for example) programmers learned a long time ago.

+46
Jul 06 '09 at 8:12
source share
 /****************************** ** File: ** Name: ** Desc: ** Auth: ** Date: ************************** ** Change History ************************** ** PR Date Author Description ** -- -------- ------- ------------------------------------ ** 1 01/10/2008 Dan added inner join *******************************/ 
+41
Jul 06 '09 at 6:52
source share
 -- -- STORED PROCEDURE -- Name of stored procedure. -- -- DESCRIPTION -- Business description of the stored procedure functionality. -- -- PARAMETERS -- @InputParameter1 -- * Description of @InputParameter1 and how it is used. -- -- RETURN VALUE -- 0 - No Error. -- -1000 - Description of cause of non-zero return value. -- -- PROGRAMMING NOTES -- Gotchas and other notes for your fellow programmer. -- -- CHANGE HISTORY -- 05 May 2009 - Who -- * More comprehensive description of the change than that included with the -- source code commit message. -- 
+19
Jul 06 '09 at 6:56
source share

We use something similar and very useful for me.

 /* Description: Author: Create Date: Param: Return: Modified Date: Modification: */ 
+10
Jul 06 '09 at 6:43
source share
 ------------------------------------------------------------------------------- -- Author name -- Created date -- Purpose description of the business/technical purpose -- using multiple lines as needed -- Copyright © yyyy, Company Name, All Rights Reserved ------------------------------------------------------------------------------- -- Modification History -- -- 01/01/0000 developer full name -- A comprehensive description of the changes. The description may use as -- many lines as needed. ------------------------------------------------------------------------------- 
+8
Mar 25 '15 at 18:41
source share
 -- [why did we write this?] -- [auto-generated change control info] 
+5
Jul 06 '09 at 6:49
source share
 set timing on <br> set linesize 180<br> spool template.log /*<br> ##########################################################################<br> -- Name : Template.sql<br> -- Date : (sysdate) <br> -- Author : Duncan van der Zalm - dvdzalm<br> -- Company : stanDaarD-Z.nl<br> -- Purpose : <br> -- Usage sqlplus <br> -- Impact :<br> -- Required grants : sel on A, upd on B, drop on C<br> -- Called by : some other process<br ##########################################################################<br> -- ver user date change <br> -- 1.0 DDZ 20110622 initial<br> ##########################################################################<br> */<br> sho user<br> select name from v$database; select to_char(sysdate, 'Day DD Month yyyy HH24:MI:SS') "Start time" from dual ; -- script select to_char(sysdate, 'Day DD Month yyyy HH24:MI:SS') "End time" from dual ; spool off 
+5
Dec 11 '12 at 8:13
source share

I know this post is ancient, but well-formatted code never goes out of style.

I use this template for all my procedures. Some people do not like the detailed code and comments, but as a person who often has to update stored procedures that have not been touched on since the mid-90s, I can tell you the value of writing well-formatted and carefully commented code. Many were written to be as concise as possible, and sometimes it may take several days to understand the meaning of the procedure. It's pretty easy to see what a block of code does by simply reading it, but it’s much harder (and sometimes impossible) to understand the meaning of the code without proper commenting.

Explain it as if you are going through a junior developer. Suppose that the person reading it knows almost nothing about the functional area to which it refers, and has a limited understanding of SQL. What for? Many times, people have to look at the procedures to understand them, even if they do not intend or the business changes them.

 /*************************************************************************************************** Procedure: dbo.usp_DoSomeStuff Create Date: 2018-01-25 Author: Joe Expert Description: Verbose description of what the query does goes here. Be specific and don't be afraid to say too much. More is better, than less, every single time. Think about "what, when, where, how and why" when authoring a description. Call by: [schema.usp_ProcThatCallsThis] [Application Name] [Job] [PLC/Interface] Affected table(s): [schema.TableModifiedByProc1] [schema.TableModifiedByProc2] Used By: Functional Area this is use in, for example, Payroll, Accounting, Finance Parameter(s): @param1 - description and usage @param2 - description and usage Usage: EXEC dbo.usp_DoSomeStuff @param1 = 1, @param2 = 3, @param3 = 2 Additional notes or caveats about this object, like where is can and cannot be run, or gotchas to watch for when using it. **************************************************************************************************** SUMMARY OF CHANGES Date(yyyy-mm-dd) Author Comments ------------------- ------------------- ------------------------------------------------------------ 2012-04-27 John Usdaworkhur Move Z <-> X was done in a single step. Warehouse does not allow this. Converted to two step process. Z <-> 7 <-> X 1) move class Z to class 7 2) move class 7 to class X 2018-03-22 Maan Widaplan General formatting and added header information. 2018-03-22 Maan Widaplan Added logic to automatically Move G <-> H after 12 months. ***************************************************************************************************/ 

In addition to this header, your code should be well-commented and outlined from top to bottom. Add comment blocks to the main functional sections, such as:

 /*********************************** ** Process all new Inventory records ** Verify quantities and mark as ** available to ship. ************************************/ 

Add a lot of inline comments explaining all but the most basic criteria, and ALWAYS format your code for easy reading. Long vertical pages of indented code are better than wide short pages and make it much easier to see where blocks of code begin and end years later when someone else supports your code. Sometimes wide, indented code is more readable. If so, use it, but only when necessary.

 UPDATE Pallets SET class_code = 'X' WHERE AND class_code != 'D' AND class_code = 'Z' AND historical = 'N' AND quantity > 0 AND GETDATE() > DATEADD(minute, 30, creation_date) AND pallet_id IN ( -- Only update pallets that we've created an Adjustment record for SELECT Adjust_ID FROM Adjustments WHERE AdjustmentStatus = 0 AND RecID > @MaxAdjNumber 
+5
Mar 22 '18 at 20:57
source share

The header we use looks like this:

 --------------------------------------------------- -- Produced By : Our company -- URL : www.company.com -- Author : me -- Date : yesterday -- Purpose : to do something -- Called by : some other process -- Modifications : some other guy - today - to fix my bug ------------------------------------------------------------ 

On the other hand, any comments that I put in SQL always use the format:

/* Comment */

As in the past, I had problems in which scripting (using SQL Server) does fun things, wrapping lines around and starting comments - comment on the required SQL ... but it can only be me.

+3
Jul 06 '09 at 8:26
source share

See if this suits your requirement:

/*

  • Notes on parameters: Give the details of all parameters supplied to the proc

  • This procedure will perform the following tasks: Give details description of the intent of the proc

  • Additional notes: Give information of something that you think needs additional mention, though is not directly related to the proc

  • Modification History: 11/07/2001 ACL TICKET / BUGID CHANGE DESCRIPTION

* /

+1
Jul 06 '09 at 8:22
source share
 -- Author: -- -- Original creation date: -- -- Description: 
0
Jul 06 '09 at 8:07
source share

Here is what I am using now. The triple comment (/ * / * / *) is for integration, which selects header comments from the object definition.

 /*/*/* Name: pr_ProcName Author: Joe Smith Written: 6/15/16 Purpose: Short description about the proc. Edit History: 6/15/16 - Joe Smith + Initial creation. 6/22/16 - Jaden Smith + Change source to blahblah + Optimized JOIN 6/30/16 - Joe Smith + Reverted changes made by Jaden. */*/*/ 
0
Jul 06 '16 at 16:15
source share

Here is my preferred option:

 /* ===================================================================== DESC: Some notes about what this does tabbed in if you need additional lines NOTES: Additional notes tabbed in if you need additional lines ======================================================================== */ 
0
Dec 13 '18 at 15:24
source share



All Articles