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 the Add New Item dialog box in the Visual Studio Templates section under My Templates. The template does not appear with the other database objects nor under Visual Studio install templates in the Add New Item dialog box.
Database Object Templates
You can find the templates for database objects in the ItemTemplates and Items folders, which are inside your installation folder for Visual Studio (such as D:\Program Files\Microsoft Visual Studio 10.0\VSTSDB\Extensions\SqlServer\ItemTemplates\). Each database schema provider has its own templates. For example, each version of SQL Server has a Table template.
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).