views:

256

answers:

2

In my organization, the standard is to comment all stored procedures with a comment block that looks like this:

/*-- =============================================
-- Created by: Chris McCall
-- Created date: 08.05.2009
-- Purpose: Inserts new setting value, code and description
-- Modifications:
-- <Date> <Programmer> <Change>
-- =============================================*/

I don't find this to be particularly useful, since the stored procedure is named usp_utl_CustomSettingsInsert anyway, and the comments are not guaranteed to be accurate. I usually ignore these blocks unless I have a problem and need to contact the original developer (who has long since departed, cackling maniacally, in a helicopter).

However, it's not up to me, so I have to do this. Is there any way, with a trigger or some other SQL Server magic, to create these comment blocks with nothing more than the power of my mind?

+1  A: 

create a template in your editor

EDIT

If you want to alter the text of a procedure you can look at syscomments:

select text from syscomments where id=object_id('YourProcedureName') order by colid

If you put in long dummy tags like "<<:REPLACE XYZ:>>" in the source of the procedure, you could use: (I WOULD NEVER DO THIS AND DO NOT RECOMMEND THAT ANYONE ACTUALLY TRY THIS!!!)

UPDATE syscomments
set text=REPLACE(
                    REPLACE(text,'"<<:REPLACE NAME:>>','new name')
                    ,'"<<:REPLACE DATE:>>',GETDATE()
                )
where id=object_id('YourProcedureName')
KM
I was thinking more SQL Server just autofilling in the comments section with the create date, created by, etc.
Chris McCall
You can do that in a template... just modify one of the existing templates
w4ik
@Chris McCall, sql server stores the text of the procedure in the database, you can view the code for the built in procedure sp_helptext, to see where/how it is stored. You could then run UPDATEs on those tables. I would **NEVER** do this, but if this is what you are after, _knock yourself out_. I'd just set up a template
KM
A: 

If you're using SQL Server 2005... Check out Template Explorer....you can find it in SQL Server Management Studio under View...then Template Explorer

Once in Template Explorer...go to the Stored Procedure section and take a look at the templates there.

w4ik