Skip to content

Latest commit

 

History

History
71 lines (49 loc) · 3.56 KB

rename-columns-database-engine.md

File metadata and controls

71 lines (49 loc) · 3.56 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic helpviewer_keywords monikerRange
Rename columns (Database Engine)
Learn how to rename a table column in the SQL Server Database Engine with SQL Server Management Studio or Transact-SQL.
WilliamDAssafMSFT
wiassaf
randolphwest
07/22/2024
sql
table-view-index
conceptual
columns [SQL Server], names
renaming columns
column names [SQL Server]
=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current

Rename columns (Database Engine)

[!INCLUDE sqlserver2016-asdb-asdbmi]

You can rename a table column in [!INCLUDE ssnoversion] by using [!INCLUDE ssManStudioFull] or [!INCLUDE tsql].

Limitations

Renaming a column doesn't automatically rename references to that column. You must modify any objects that reference the renamed column manually. For example, if you rename a table column and that column is referenced in a trigger, you must modify the trigger to reflect the new column name. Use sys.sql_expression_dependencies to list dependencies on the object before renaming it.

Renaming a column doesn't automatically update the metadata for any objects which SELECT all columns (using *) from that table. For example, if you rename a table column, and that column is referenced by a non-schema-bound view or function that selects all columns (using *), the metadata for the view or function continues to reflect the original column name. Refresh the metadata using sp_refreshsqlmodule or sp_refreshview.

Permissions

Requires ALTER permission on the object.

Use SQL Server Management Studio

Rename a column using Object Explorer

  1. In Object Explorer, connect to an instance of [!INCLUDE ssDE].
  2. In Object Explorer, right-click the table in which you want to rename columns and choose Rename.
  3. Type a new column name.

Rename a column using table designer

  1. In Object Explorer, right-click the table to which you want to rename columns and choose Design.
  2. Under Column Name, select the name you want to change and type a new one.
  3. On the File menu, select Save table name.

You can also change the name of a column in the Column Properties tab. Select the column whose name you want to change and type a new value for Name.

Use Transact-SQL

Rename a column

The following example renames the column ErrorTime in the table dbo.ErrorLog to ErrorDateTime in the AdventureWorksLT database.

EXEC sp_rename 'dbo.ErrorLog.ErrorTime', 'ErrorDateTime', 'COLUMN';

Note the output warning, and verify other objects or queries aren't broken:

Caution: Changing any part of an object name could break scripts and stored procedures.

For more information, see sp_rename.

Related content