Click here to monitor SSC

FatherJack

SQL Q+A forum at ask.sqlservercentral.com | Follow fatherjack on Twitter

Comments - What's that?!!

Published Thursday, March 31, 2011 2:00 PM


This blog entry is not one of mine. I have the pleasure of sitting back and letting someone else do the work! Ladies and gentlemen, this blog is written by ..... my wife!

I have recently changed job, in my previous job our Senior DBA, also my husband, and better known to all of you as Fatherjack used to nag me like crazy about my lack of comments. Even when I did comment it wouldn't be good enough and I couldn't understand what I was doing wrong.
Most of the work I have been doing since I started my new role has been investigating scripts, the systems are made up of various databases which pass data between other servers and additional databases and I have to try to track the data back and how it gets from source to final output.

The legacy scripts have little or no comments, however my new boss has very stringent rules on commenting and provides his team with clear guidelines on what is expected and the scripts that use his guidelines are excellent. However, this is not the case with legacy scripts which go back up to 10 years, which is 8 years longer than my boss. The comments, if there are any, state the obvious, for example,

-- this inserts A into B
INSERT INTO TableA
    
SELECT Name
    
FROM TableB

I understand this I can read the TSQL! What I want to know is why is it doing it. Why is it getting the data from A and putting it in B, what's the purpose of this script?

I am a firm believer that all scripts should start with a clear set of guidance to show the purpose and of course when and why it changed, for example:

/******************************************************************** 
Description: Purpose: Created On: Created By: Version Date Updated       Updated By      Changes Made    Reason for change ********************************************************************/

Then each part of  the script should explain what it's individual purpose is. For example:

/*  Looks for duplicates in table x and stores them in a temporary table for later use */

The other part of commenting that I think is equally important, is that when a change is made to a script that not only is the version in the header fully updated, but also where the change is made is also commented fully, especially when code is no longer required, this should not be deleted but just commented out.

/********************************************************************
 Changed: March 2011 by Joe Bloggs
 To amend the where clause to allow products that  begin with 'C'
********************************************************************/

By following these very simple guidelines those people who come in after you to look at your code have got a better than average chance of working out what you were doing and why you were doing it.  Sorry Fatherjack, I realise the error of my ways now and confirm that I will no longer leave my scripts with little or no comments.

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

What do you think?

(required) 
(optional)
(required) 

About fatherjack

DBA since 1999 working for not-for-profit company. http://twitter.com/fatherjack,
Latest articles
Checking Out SQL Backup Pro 7’s New Automatic Backup Verification
 Wouldn't it be great to offload the daily chore of checking the integrity of your production... Read more...

Chuck Lathrope: DBA of the Day
 Chuck Lathrope was a finalist for the Exceptional DBA of the Year award in 2009. We contacted him to... Read more...

Backups, What Are They Good For?
 Pixar recently confessed, in an engaging video, that Toy Story 2 was almost lost due to a bad backup,... Read more...

C# Async: What is it, and how does it work?
 The biggest new feature in C#5 is Async, and its associated Await (contextual) keyword. Anybody who is... Read more...

SQL Server 2012 AlwaysOn
 SQL Server AlwaysOn provides a high-availability and Disaster-recovery solution for SQL Server 2012. It... Read more...