| title | Delete Columns from a Table | Microsoft Docs | ||||
|---|---|---|---|---|---|
| ms.custom | |||||
| ms.date | 04/11/2017 | ||||
| ms.prod | sql | ||||
| ms.prod_service | table-view-index, sql-database, sql-data-warehouse, pdw | ||||
| ms.reviewer | |||||
| ms.technology | table-view-index | ||||
| ms.topic | conceptual | ||||
| helpviewer_keywords |
|
||||
| ms.assetid | 0d8f6e4f-bc71-4fa3-8615-74249c8e072d | ||||
| author | stevestein | ||||
| ms.author | sstein | ||||
| monikerRange | >=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||=sqlallproducts-allversions||>=sql-server-linux-2017||=azuresqldb-mi-current |
[!INCLUDEtsql-appliesto-ss2016-all-md]
This topic describes how to delete table columns in [!INCLUDEssCurrent] by using [!INCLUDEssManStudioFull] or [!INCLUDEtsql].
Caution
When you delete a column from a table, it and all the data it contains are deleted.
In This Topic
-
Before you begin:
-
To delete a column from a table, using:
You cannot delete a column that has a CHECK constraint. You must first delete the constraint.
You cannot delete a column that has PRIMARY KEY or FOREIGN KEY constraints or other dependencies except when using the Table Designer. When using Object Explorer or [!INCLUDEtsql], you must first remove all dependencies on the column.
Requires ALTER permission on the table.
- In Object Explorer, connect to an instance of [!INCLUDEssDE].
- In Object Explorer, locate the table from which you want to delete columns, and expand to expose the column names.
- Right-click the column that you want to delete, and choose Delete.
- In Delete Object dialog box, click OK.
If the column contains constraints or other dependencies, an error message will display in the Delete Object dialog box. Resolve the error by deleting the referenced constraints.
- In Object Explorer, right-click the table from which you want to delete columns and choose Design.
- Right-click the column you want to delete and choose Delete Column from the shortcut menu.
- If the column participates in a relationship (FOREIGN KEY or PRIMARY KEY), a message prompts you to confirm the deletion of the selected columns and their relationships. Choose Yes.
The following example shows you how to delete a column.
ALTER TABLE dbo.doc_exb DROP COLUMN column_b;If the column contains constraints or other dependencies, an error message will be returned. Resolve the error by deleting the referenced constraints.
For additional examples, see ALTER TABLE (Transact-SQL).