| title | Delete Columns from a Table | Microsoft Docs | ||||
|---|---|---|---|---|---|
| ms.custom | |||||
| ms.date | 06/13/2017 | ||||
| ms.prod | sql-server-2014 | ||||
| ms.reviewer | |||||
| ms.technology | table-view-index | ||||
| ms.topic | conceptual | ||||
| helpviewer_keywords |
|
||||
| ms.assetid | 0d8f6e4f-bc71-4fa3-8615-74249c8e072d | ||||
| author | stevestein | ||||
| ms.author | sstein | ||||
| manager | craigg |
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 from the database. This action cannot be undone.
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, right-click the table from which you want to delete columns 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.
-
In Object Explorer, connect to an instance of [!INCLUDEssDE].
-
On the Standard bar, click New Query.
-
Copy and paste the following example into the query window and click Execute.
USE AdventureWorks2012; GO 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).