Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Stupidest Newbie Question Ever - Headers

Author  Topic 

Tristan.Wolf
Starting Member

5 Posts

Posted - 2006-05-03 : 10:21:09
First off, I wanted to let you guys know that this is simply one of the best SQL resource websites on the planet. I am astonished to see the level of detail, help, teamwork, and such here. Someone needs to point me in the direction of the page that explains how we can help support the site.

At any rate, I really do have the stupidest question ever. If any of you guys and gals get to know me, you'll quickly find that I'm very good at asking the dumbest questions. hehe

Basically, I want to create a template that I can insert into every Query Analyzer file that helps me create / track that query. I haven't gotten very far with it, though.

/*	Set query options */
-- Do not automatically return the affected row count after each Transact-SQL statement is processed.
SET NOCOUNT ON
GO
/* Set database context */
-- Define the default database to use when no database has been explicitly qualified.
USE wcc_as400
GO


I would like to preceed this with some comments, but I am unsure of what to include and what would be a good style to use for it. I'm thinking something along the lines that gives name, version, developer, date created, change tracking, and anything else that would be important to include.

So, can anyone please help me? I am looking for some good ideas on what information to include at the beginning of all queries that would assist in development, and what style is easy to maintain.

Thanks, in advance, for your help!

twhelan1
Yak Posting Veteran

71 Posts

Posted - 2006-05-03 : 11:41:41
We use something along the lines of

/************************************************
* Name: getReportDetail
* Created By: twhelan
* Create Date: 1/1/06
* Purpose: Returns the report detail
*
* Change Control
* - 1/1/06 - Create - twhelan
* - 1/30/06 - Added sum column on cost - twhelan
**************************************************


Then in addition, add comments any place that changes were made to describe what was changed and why (in case those changes introduce a bug that isn't caught in testing and a different developer gets stuck trying to fix that bug).

We also store the Create Procedure scripts in source control in case we have to roll back to a previous version.

~Travis
Go to Top of Page

twhelan1
Yak Posting Veteran

71 Posts

Posted - 2006-05-03 : 11:41:42
Somehow hit reply twice (I'm a noob!)
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-05-03 : 11:51:08
I just wanted to say that your question was far from "the stupidest question ever". Or even today.

If you want that honor, you're going to have to try a lot harder.




CODO ERGO SUM
Go to Top of Page

Tristan.Wolf
Starting Member

5 Posts

Posted - 2006-05-03 : 14:39:39
Okay. Thank you very much, twhelan, for the response. I basically took exactly what you had. The differences are due to some additional considerations:

- I would like to be able to print any script without destroying the formatting due to word wrap.
- The best I could tell is that 78 characters width is going to fit on just about every printer ever (no idea how to confirm this though).
- To note, I have set my tabs to be four (4) characters long and not to convert to spaces.

- I have added an additional GO, even though it does nothing. Did this because I use ApexSQL Edit instead of Query Analyzer, and this makes the code look a little better.

- Converted data to Template Parameters for easy use.

Please review the following. Any comments / suggestions are more than welcomed. After all, the purpose of me being here is so the folks that know (read: you) can pass on some info to the folks that don't (read: me) :)

Thank you very much!

/*	**********************************************************************	*/
-- Name: <script_name, nvarchar(62), to_be_determined>
-- Created by: <current_developer_name, nvarchar(62), initial_developer>
-- Created on: <todays_date, nvarchar(10), mm/dd/yyyy>
-- Purpose: <purpose_of_script, nvarchar(62), to_be_determined>
--
-- Change Control
-- <todays_date, nvarchar(10), mm/dd/yyyy> <current_developer_name, nvarchar(62), initial_developer>
-- >> Create
/* ********************************************************************** */
GO
/* Set query options */
-- Do not automatically return the affected row count after each Transact-SQL
-- statement is processed.
SET NOCOUNT ON
GO
/* Set database context */
-- Define the default database to use when no database has been explicitly
-- qualified.
USE <default_database, nvarchar(123), master>
GO


EDIT 1 - Forgot to change database to a template parameter.
EDIT 2 - After playing with this, made some minor changes to formatting and defaults.
Go to Top of Page

Tristan.Wolf
Starting Member

5 Posts

Posted - 2006-05-08 : 09:01:31
Okay. Did a little more work on this one. Hoping someone can review for me, just to make sure I'm not a complete baffoon (maybe 95%...lol).

First, the meat and potatoes: the header template itself:

/*	**********************************************************************	*/
-- Name: <script_name, nvarchar(62), to_be_determined>
-- Created by: <current_developer_name, nvarchar(62), initial_developer>
-- Created on: <todays_date, nvarchar(10), mm/dd/yyyy>
-- Purpose: <purpose_of_script, nvarchar(62), to_be_determined>
--
-- Change Control
-- <todays_date, nvarchar(10), mm/dd/yyyy> <current_developer_name, nvarchar(62), initial_developer>
-- >> Create
/* ********************************************************************** */
GO
/* Set query options */
-- Do not automatically return the affected row count after each Transact-SQL
-- statement is processed.
SET NOCOUNT ON
GO
/* Set database context */
-- Define the default database to use when no database has been explicitly
-- qualified.
USE <default_database, nvarchar(123), master>
GO
/* Description of following code */
--

GO


I can't think of anything else I can / should add to this to make it better or easier to use. All suggestions are more than welcomed, of course.

Now, a few helper templates...

Because of the 78 character width that I mentioned before, I have this simple template, called Maximum Length of a Line, to help me measure out lines:


/************************************0078************************************/


I'm sure this isn't the best way to handle this, but no idea how else to play with it.

Finally, I have another template, called Change Control Entry, that will help with adding an additional entry there:


-- <todays_date, nvarchar(10), mm/dd/yyyy> <current_developer_name, nvarchar(62), initial_developer>
-- >> <description_of_change, nvarchar(67), initial_developer>


Not sure if this is too good either.

Appreciate all of the help guys and gals. :)

Go to Top of Page

Tristan.Wolf
Starting Member

5 Posts

Posted - 2006-05-08 : 09:09:14
Something's wrong with the 3rd template.

It's not picking up the 2nd parameter correctly. Still working on it. Again, all feedback / help is very much appreciated.

Thank you.
Go to Top of Page
   

- Advertisement -