visual-studiosql-server-2005code-snippetscode-templates

How to create a new stored procedure template for Visual Studio?


I would like to create a template for new stored procedures for our development team.

However, I can't seem to create template items for Database objects. I know for DLL/C#-related items, it's as simple as "File > Export Template ..."

How can I add new SQL templates to my Database project?

Here's my template:

IF EXISTS (select 1 from information_schema.routines where specific_schema = '_SCHEMA_' and routine_name = '_NAME_')
    BEGIN
        print 'Dropping Procedure _SCHEMA_._NAME_'
        DROP  Procedure  _SCHEMA_._NAME_
    END
GO

print 'Creating Procedure _SCHEMA_._NAME_'
GO
CREATE Procedure _SCHEMA_._NAME_
    (
        @parameter1 int
    ,   @parameter2 varchar(10)
    )
AS
BEGIN

END
GO

GRANT EXEC ON _SCHEMA_._NAME_ TO _ROLE_
GO

Thanks!

Edit: Wow, it's the first time I've had a question a whole day without any answers!

Is it just me, or does no one else use Item Templates? I lead a number of developers, and it's easier to tell them "use this template" vs. "read the docs and do it that way".


Solution

  • Found it.

    Here is the folder with the files:

    C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\Templates\Database Project Items

    It's straight-forward to replace the New Stored Procedure Script.sql with your own. If you want to add one (which I did) you can edit the NewDataItems.vsdir file to show a custom icon.