Creating a Table Script in a Database Project
Tue, Jul 30 2013 12:50
Visual Studio 2012 introduced a new SQL Server Database Project. This post details how to create a new table script in your Database Project.
See this link for an introduction to the Visual Studio 2012 SQL Server Database Project.
To create a new table in a SQL Server Database Project:
1) In Solution Explorer, drill down into your SQL Server Database Project to dbo then to Tables.
2) Right-click on Tables and select Add | Table.
3) Enter the desired table name and click Add.
4) A script is added to the project for the new table:
5) The Table Designer is opened for entry of the table detail:
6) Use the Table Designer pane at the top OR the T-SQL pane on the bottom to define the columns for the table.
The two panes are kept in sync automatically.
7) Use the Properties window (View | Properties Window) to set additional properties for the fields on the table, such as the Identity information.
8) The defined properties are added to the script in the T-SQL pane:
9) When you have finished, click Save to save the script to the project.
Notice that there is no Update button on this designer. The table is not added to a database at this point. To update the database with the details from the new script, you need to publish the Database Project.
See this link for details on publishing a Database Project.
Use the Database Project to add table scripts instead of adding a table directly to your development database.