How to: Delete Objects and Resolve Dependencies
When you rename or delete an object in SQL Server Object Explorer, SQL Server Data Tools automatically detects all its dependency objects, and will prepare an ALTER script to rename or drop the dependency as needed.
The following procedures uses entities created in previous procedures in the Connected Database Development section.
To delete a database
Right-click a database in SQL Server Object Explorer, and select Delete.
Accept all the default settings in the Delete Database dialog, and click OK.
To rename a table
Make sure that the
Customertable is not opened in either the Table Designer or the Transact-SQL Editor.
Expand the Tables node in SQL Server Object Explorer. Right-click the Customer table and select Rename.
Change the table name to Customers and press ENTER.
Notice that a Database Update operation is immediately invoked on your behalf. SSDT will call the sp_rename stored procedure on your behalf to rename the table. If there are any dependent objects such as foreign key constraints, they will also be updated.
Script-based dependencies such as references to a table from a view, or stored procedures are not automatically updated by SSDT. After the rename, you can use the Error List pane to locate all other dependencies and manually fix them.
Apply the change following the steps in the previous How to: Update a Connected Database with Power Buffer procedure.
Right-click the Customers table in SQL Server Object Explorer again, and select View Data. Notice that table data is intact after the rename operation.
Right-click the Products table and select View Code. Notice that the foreign key reference has been automatically updated to
REFERENCES [dbo].[Customers] ([Id])to reflect the renaming.
To delete a table
Right-click the Customers table in SQL Server Object Explorer, and select Delete.
In the Preview Database Updates dialog, under User Action, notice that SSDT has identified all the dependent objects, in this case, a foreign key reference that will be dropped.
Click Update Database.
Right-click the Products table in SQL Server Object Explorer, and select View Code. Notice that the foreign key reference to the
Customerstable is gone.
If you already have the Products table opened in Table Designer or Transact-SQL Editor when the delete operation occurs, it will not automatically refresh to show the deletion of the foreign key reference. In addition, errors about unresolved references may show up in the Error List. To resolve this issue, close the Table Designer or Transact-SQL Editor, and reopen the Products table.