Examples of a template to documenting your scripts.

  • Hello,

    My manager wants me to go through every one's script and put them in one format. Then I will load them into a verson control software.

    I have never seen a standard for creating scripts. I know in QA, you can set up templates to help as you create scripts. But I don't know that I've ever seen a standard as far as how a well written script.

    I know some scripts have headings, some have a change history at the top, who have who created it, etc.

    Does anyone have an example or know of somewhere online where I can find examples of well written scripts that I can use an example? I will use this a template for all our scripts.

    We use SQL Server 2000, 2005 and 2008. But I will only be taking scripts created by developers using query analzyer and reformatting them.

    Thanks,

    Tony

    Things will work out.  Get back up, change some parameters and recode.

  • There's 2 things here. One is reformatting, one is documenting.

    For reformatting, I'd get a tool. You'll waste the cost of the tool easy in doing this by hand. Red Gate (I work for them) has SQL Refactor () that will help. Apex SQL, other companies have others.

    For documenting, I'd add a quick author, description at the top of a script. Lots of people do things like:

    /*******************************************************

    Name:

    Author:

    Description:

    Changes:

    Mar 3 2009 jsj - Added new parameter for unit cost

    Jan 4 2009 mlk - Added the total cost to the result set

    Nov 5 2008 jsj - added logic for xxx

    ********************************************************/

    You can add parameters, but I think defining them is tedious, and annoying. You can add the outputs, but I think the same thing applies. You're documenting for other technical people, so explain what you need to, but understand that they are smart enough to decode this.

    I do like to see a change log at the top, reverse chronology, as I've shown.

  • Thanks Steve for helping.

    I guess, based on your answser, I am referring to documenting.

    My boss said, "Put them all in the same format and load them in our version control software package (similiar to VSS)."

    I usually have a heading somewhat you did.

    1) I'm not sure why you do reverse chronology? Then you have to insert it. It is usually easier to add to the bottom. But it would be great to hear your reasoning.

    2) I didn't know if there was a guru's example for documenting scripts that other dba's use as a policy when they or their team develops scripts.

    3) Our scripts are all written in T-SQL.

    4) I come from a ETL/BI/DBA background, but the other guys from old school DBA backgrounds. A lot of code to create cursors, but not a lot of commenting. You have to really go through it to understand what the dba was meaning to do. Which is probably why my manager wanted me to go through and create a template for all developers/dba to use as they develop stored procedures/T-SQL scripts.

    Hope that explains what I am trying to do!

    Thanks again. I love this forum! I get so much from gleening from the experience of DBA gurus.

    Tony

    Things will work out.  Get back up, change some parameters and recode.

  • I use reverse chronology so that I see the changes first when I'm looking. Over time when there are lots of changes, it's easy to get a little lost at the top.

    If you have really complex scripts, I'd have people comment sections to keep things straight. The best way to do this is force code reviews before you put something into VSS. Have another developer see if it makes sense, or has enough comments for them to understand it. We used to designate a person for a month to review code. They still wrote code, but they were the person reviewing it all, which gave them a sense of ownership.

    I don't know of a great standard out there. A header is the best if you can enforce it.

  • Thanks Steve. This looks like it will be an interesting project.

    Things will work out.  Get back up, change some parameters and recode.

Viewing 5 posts - 1 through 4 (of 4 total)

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