An Overview of Templates for Database and Server Objects
When you add an item to a database project, the default definition for that item comes from a prototype called a project item template. You can customize existing templates. You might decide to customize existing templates if, for example, you wanted to add comments to all the templates that your team uses. If you find yourself creating similar objects, even in different databases, creating a custom template can help save work.
Working with Templates
The following topics contain information about project item templates and how you can use them to create your own database project items:
Introduction to Visual Studio Templates
Describes Visual Studio templates and what they contain.Visual Studio Template Metadata Files
Explains the .vstemplate files that are required for templates.Differences Between Project and Item Templates
Explains the differences in contents and usage between project and item templates.Creating Item Templates
Contains links to topics that explain how to create item templates.How to: Locate and Organize Project and Item Templates
Explains the folders that Visual Studio examines when it looks for templates.Customizing Project and Item Templates
Contains topics that describe how to customize project and item templates.
Note
When you export a project template or an item template from a database project, your custom template will appear in Visual Studio Templates under My Templates. The template will not appear in the Database Project templates under My Templates in the Add New Item dialog box.
Database Object Templates
You can find the templates for database objects in the \DBPro\ItemTemplates\ and \DBPro\Items folders, which are inside your installation folder for Microsoft Visual Studio 2005. Microsoft SQL Server 2000 and SQL Server 2005 also have their own templates.
Replaceable Parameters in Database Object Templates
You can use the following replaceable parameters within the .sql files in your database object templates:
$ChildObjectName$
Contains the name of the child database object. Use this when you define templates for items such as indexes, where the object that you are defining has a parent-child relationship to another database object.$ParentObjectName$
Contains the name of the parent database object. Use this when you define templates for items such as indexes, where the object that you are defining has a child-parent relationship to another database object.$rawname$
Contains the unmodified name that the user gives to the object in the Add New Item dialog box. Use this when you define templates for objects such as users or roles.$SchemaName$
Contains the name of the database schema. Use this when you define templates for items such as indexes, where the object you are defining has a child-parent relationship to another database object. You should prefix the parent object name with the schema name. For example, you can specify: ALTER TABLE[$SchemaName$].[$ParentObjectName$]ADD CONSTRAINT[$ChildObjectName$]UNIQUE(column_1).$SchemaQualifiedObjectName$
Contains the schema-qualified object name. Use this, for example, in the create table script: CREATE TABLE $SchemaQualifiedObjectName$ (col1 INT NOT NULL).
See Also
Concepts
Terminology Overview of Database Edition