Adding Tables with SSDT

Posted Sun, Oct 21 2012 23:12 by Deborah Kurata

OK, no more SSDT jokes! SSDT, or SQL Server Data Tools, give you the features of SQL Server Management Studio within Visual Studio 2012. You can use the SQL Server Object Explorer from the SSDT to create and maintain tables in your databases.

See this link for an introduction to SQL Server Object Explorer.

See this link for details on creating a new database with SSDT.

To add a new table to a SQL Server database:

1) Open the SQL Server Object Explorer toolbox using View | SQL Server Object Explorer from Visual Studio.

2) Drill down to the Databases node, then to your database, then to Tables.

3) Right-click and select Add New Table...

image

4) Visual Studio creates a new table called "Table" and opens it in the Table designer.

image

At this point you can use the design grid in the upper left panel or the T-SQL in the bottom panel or any combination of both to define your table.

In the example below, the LastName was added in the upper left panel. Notice that Visual Studio automatically generates the matching T-SQL:

image

In this example, the FirstName field was added in the T-SQL. Notice that Visual Studio automatically generates the matching row in the grid:

image

To name the table, edit the Create Table statement in the T-SQL.

image

You can use the Properties window (View | Properties Window) to set additional properties for the fields on the table, such as the Identity information.

image

When you are done with the table design, click the Update button in the upper left corner. Visual Studio presents a preview dialog:

image

Click Generate Script to create a deployment script containing the T-SQL. Click Update Database to directly update the database with the new table.

A few issues I have had working with the Table designer:

  • There are sometimes issues when the Table designer is not docked to the main window, meaning that it is either floating or docked to another tab raft (say on a second monitor). At some point, the window stops accepting keyboard input. I have to then re-dock the window to type anything more.
  • The only way I was able to get the primary key to be named (instead of unnamed) is to remove the primary key and reset it after naming the table.
  • I was not able to set the table's name using the Properties window.

Use the SQL Server Object Explorer any time you need to add or edit the table structure of your database.

Enjoy!

Filed under: , , , , ,

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: