| title | Add Columns to a Table (Database Engine) | Microsoft Docs | |||
|---|---|---|---|---|
| ms.custom | ||||
| ms.date | 10/27/2016 | |||
| 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 | abeb8d52-d562-4e29-9e1e-2923ae874859 | |||
| 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 article describes how to add new columns to a table in [!INCLUDEssCurrent] by using [!INCLUDEssManStudioFull] or [!INCLUDEtsql].
Using the ALTER TABLE statement to add columns to a table automatically adds those columns to the end of the table. If you want the columns in a specific order in the table, use [!INCLUDEssManStudioFull]. However, note that this is not a database design best practice. Best practice is to specify the order in which the columns are returned at the application and query level. You should not rely on the use of SELECT * to return all columns in an expected order based on the order in which they are defined in the table. Always specify the columns by name in your queries and applications in the order in which you would like them to appear.
Requires ALTER permission on the table.
-
In Object Explorer, right-click the table to which you want to add columns and choose Design.
-
Click in the first blank cell in the Column Name column.
-
Type the column name in the cell. The column name is a required value.
-
Press the TAB key to go to the Data Type cell and select a data type from the dropdown.
This is a required value, and will be assigned the default value if you don't choose one.
[!NOTE] You can change the default value in the Options dialog box under Database Tools.
-
Continue to define any other column properties in the Column Properties tab.
[!NOTE] The default values for your column properties are added when you create a new column, but you can change them in the Column Properties tab.
-
When you are finished adding columns, from the File menu, choose Save table name.
The following example adds two columns to the table dbo.doc_exa.
ALTER TABLE dbo.doc_exa ADD column_b VARCHAR(20) NULL, column_c INT NULL ;