|
| 1 | +--- |
| 2 | +title: Add Database Objects Using Item Templates |
| 3 | +description: Use the SQL Database Projects extension for Visual Studio Code to add common database objects to your project using item templates. |
| 4 | +author: rwestMSFT |
| 5 | +ms.author: randolphwest |
| 6 | +ms.reviewer: iqrashaikh |
| 7 | +ms.date: 02/10/2026 |
| 8 | +ms.service: sql |
| 9 | +ms.subservice: sql-database-projects |
| 10 | +ms.topic: how-to |
| 11 | +--- |
| 12 | + |
| 13 | +# Add database objects using item templates |
| 14 | + |
| 15 | +Use the SQL Database Projects extension for Visual Studio Code to add common database objects to your project using item templates. Item templates generate properly formatted Transact-SQL (T-SQL) files with standard boilerplate code, helping you maintain consistency across your database schema. |
| 16 | + |
| 17 | +Database objects added to a SQL project are validated during the project build. This validation helps you catch syntax and reference problems early, before deployment starts. |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | + |
| 21 | +- Visual Studio Code installed |
| 22 | +- The SQL Database Projects extension |
| 23 | +- An existing SQL database project (`.sqlproj`) |
| 24 | + |
| 25 | +## Available item templates |
| 26 | + |
| 27 | +The SQL Database Projects extension includes the following item templates: |
| 28 | + |
| 29 | +| Template | Description | |
| 30 | +| --- | --- | |
| 31 | +| **Schema** | Creates a new database schema for organizing database objects into logical groups. | |
| 32 | +| **Table-Valued Function** | Creates a function that returns a table result set. | |
| 33 | +| **Sequence** | Creates a sequence object that generates sequential numeric values. | |
| 34 | +| **Trigger** | Creates a DML trigger that runs when `INSERT`, `UPDATE`, or `DELETE` operations occur on a table or view. | |
| 35 | +| **Database Trigger** | Creates a DDL trigger that runs in response to database-level events. | |
| 36 | + |
| 37 | +## Add an item to your project |
| 38 | + |
| 39 | +Add database objects to your project using item templates from the Database Projects view. |
| 40 | + |
| 41 | +1. In the Database Projects view, right-click your SQL project or an included folder. |
| 42 | + |
| 43 | + > [!NOTE] |
| 44 | + > To keep larger projects manageable, many SQL projects organize files by schema and object type. For example, you might use `dbo/Tables` or `sales/Views`. |
| 45 | +
|
| 46 | +1. Select **Add Item**. |
| 47 | + |
| 48 | +1. Select the type of object you want to create. |
| 49 | + |
| 50 | +1. Enter a name for the new object. |
| 51 | + |
| 52 | +::: image type="content" source="media/add-item-templates/add-item-menu.png" alt-text="Screenshot of context menu showing Add Item option." lightbox="media/add-item-templates/add-item-menu.png"::: |
| 53 | + |
| 54 | +The extension creates a T-SQL file in your project with template code for the selected object type. |
| 55 | + |
| 56 | +> [!NOTE] |
| 57 | +> You can also add items using the Command Palette. Press **Ctrl**+**Shift**+**P** (Windows/Linux) or **Cmd**+**Shift**+**P** (macOS), and then type **SQL Database Projects: Add Item**. |
| 58 | +
|
| 59 | +## Template examples |
| 60 | + |
| 61 | +These examples show the T-SQL code generated by item templates. |
| 62 | + |
| 63 | +### Schema |
| 64 | + |
| 65 | +The schema template creates a file with a `CREATE SCHEMA` statement: |
| 66 | + |
| 67 | +:::image type="content" source="media/add-item-templates/schema-template.png" alt-text="Screenshot of generated schema file." lightbox="media/add-item-templates/schema-template.png"::: |
| 68 | + |
| 69 | +### Table-valued function |
| 70 | + |
| 71 | +The table-valued function template includes parameter and return table placeholders: |
| 72 | + |
| 73 | +:::image type="content" source="media/add-item-templates/table-valued-function-template.png" alt-text="Screenshot of generated table-valued function." lightbox="media/add-item-templates/table-valued-function-template.png"::: |
| 74 | + |
| 75 | +Modify the parameter names, data types, and return table columns to match your requirements. |
| 76 | + |
| 77 | +## Related content |
| 78 | + |
| 79 | +- [Publish SQL database projects from Visual Studio Code](publish-database-project.md) |
| 80 | +- [Get started with the SQL Database Projects extension](getting-started-sql-database-projects-extension.md) |
| 81 | +- [What are SQL database projects?](../../sql-database-projects/sql-database-projects.md) |
| 82 | +- [CREATE SCHEMA (Transact-SQL)](../../../t-sql/statements/create-schema-transact-sql.md) |
| 83 | +- [CREATE FUNCTION (Transact-SQL)](../../../t-sql/statements/create-function-transact-sql.md) |
0 commit comments