How to: Delete Database Objects

To delete a database object from a database project, you can delete the object from Schema View, or you can delete the file that contains the object definition from Solution Explorer. You must follow a different process to delete table columns and the parameters of a stored procedure or function. After you delete one or more objects from a database project, you must build and deploy the changes to your database server.

Deleting Database Objects

To delete an object from a database project

  1. If Schema View does not appear, open the View menu and click Schema View.

  2. In Schema View, click the object that you want to delete.

  3. On the Edit menu, click Delete. You can also click the object and press the DELETE key.

    A confirmation dialog box appears.

  4. Click OK in the confirmation dialog box.

    The object is deleted from the database project in both Solution Explorer and Schema View. If the database project is under version control, when you delete the object, the project file will be checked out. Deleting an object from Schema View also deletes all child objects. For example, if you delete a table, all keys, triggers, indexes, constraints, and statistics are also deleted.

    For the change to be reflected on the database server, you must build and deploy your changes. For more information, see How to: Prepare Database Build Scripts.

To delete the file that contains an object definition from a database project

  1. In Solution Explorer, click the file that represents the object that you want to delete.

  2. On the Edit menu, click Delete. You can also click the object and press the DELETE key.

    A confirmation dialog box appears.

  3. Click OK in the confirmation dialog box.

    The object is deleted from the database project in both Solution Explorer and Schema View. If the database project is under version control, when you delete the object, the project file will be checked out. If the object you deleted had child objects, such as indexes or keys on a table, the child objects will appear in the Orphaned Objects folder in Schema View. Errors will appear in the Error List indicating that the parent object cannot be found.

    For the change to be reflected on the database server, you must build and deploy your changes. For more information, see How to: Prepare Database Build Scripts.

Deleting Columns and Parameters

A few types of objects appear in Schema View, even though you cannot delete them from Schema View. The examples are columns in a table and parameters of a stored procedure or function. Both these types of objects appear in Schema View so that you can better understand the table, procedure, or function without having to open its definition. However, each column and parameter is defined within the file that defines the entire table, procedure, or function. To delete these items, you must modify the definition for the table, procedure, or function.

To delete a column from a table

  1. If Schema View does not appear, open the View menu, point to Other Windows, and click Schema View.

  2. In Schema View, click the table that contains the column that you want to delete.

    - or -

    In Solution Explorer, click the file containing the table that contains the column that you want to delete.

  3. On the View menu, click Open.

    The file that contains the table definition opens in the Transact-SQL (T-SQL) editor.

  4. Modify the table definition to remove the column that you want to delete.

  5. On the File menu, click Save TableName**.Table.sql**.

    The changes are saved, and the table definition is updated in Schema View. The column that you deleted no longer appears.

To delete a parameter from a stored procedure or function

  1. If Schema View does not appear, open the View menu, point to Other Windows, and click Schema View.

  2. In Schema View, click the stored procedure or function that contains the parameter that you want to delete.

  3. On the View menu, click Open.

    The file that contains the procedure or function definition opens in the Transact-SQL (T-SQL) editor.

  4. Modify the procedure or function definition to remove the parameter that you want to delete.

  5. On the File menu, click Save ProcedureName**.proc.sql** or Save FunctionName.function.sql.

    The changes are saved, and the procedure or function definition is updated in Schema View. The parameter that you deleted no longer appears.

See Also

Tasks

How to: Create a Database Object
How to: Modify Database Objects

Concepts

Working with Database Objects
Terminology Overview of Team Edition for Database Professionals

Other Resources

Building and Deploying Version-controlled Databases