How to: Use the Table Designer to Manage Tables and Relationships
The Table Designer provides a visual experience alongside the Transact-SQL Editor for creating and editing table structure, including table-specific programming objects, for SQL Server databases. It is launched when you create a new table for a connected database or a project, or when you double-click to edit a table in either SQL Server Object Explorer or Solution Explorer.
The designer consists of the Columns Grid, Script Pane and Context Pane. The Columns Grid lists all the columns in the table. You can add, edit and delete columns in this grid. The Context Pane gives you a logical view of the table definition (Keys, Indices, Constraints, Triggers, etc.), and enables you to select an object to highlight its relationships to individual columns. You can also add new objects to the table in this pane, and edit the properties of a selected object in the Properties Grid. Script Pane shows you the definition of the table structure, and highlights the script of the selected object in the Context Pane or Columns Grid. You can edit the script side-by-side with the Columns Grid and Context Pane in view. Any changes from any of the three panes will propagate to the other two immediately.
Warning
The following procedure uses entities created in previous procedures in the Project-Oriented Offline Database Development sections.
To create a new table
Open the TradeDev project you have been working on in previous procedures.
In Solution Explorer, expand the dbo folder, right-click the Tables folder and select Add, then Table.
Name the new table Shipper and click Add.
The Table Designer opens. In the Columns Grid, add a new column to the table with name ShipperName and Data Type int.
Notice that you can also edit the properties of columns in the Properties window. Click the ShipperName column, and in the Properties window, change the DataType of this column to nvarchar, and length to 128. Notice that as you shift your focus out of the field, the Script Pane and the Columns Grid of the designer automatically update to reflect your change.
To create a new foreign key constraint
Right-click the Foreign Keys node in the Context Pane of the designer, and select Add New Foreign Key.
Notice that the node count automatically increments by 1. Press ENTER to accept the default name of the constraint.
Replace the default definition of the constraint in the Script Pane with the following.
CONSTRAINT [FK_Shipper_Products] FOREIGN KEY ([Id]) REFERENCES [dbo].[Products]([Id])
Notice the experience of creating and editing database entities for an offline project is identical to performing the tasks with a connected database.