Home

Transact-SQL: Renaming a Column

 

Introduction

To rename a column, first open an empty Query Editor. In a Query Editor, execute sp_rename using the following formula:

sp_rename 'TableName.ColumnName', 'NewColumnName', 'COLUMN'

The sp_rename factor and the 'COLUMN' string are required. The TableName factor is the name of the table that the column belongs to. The ColumnName is the current name of the column. The NewColumnName is the desired name you want to give to the column.

Here is an example:

sp_rename 'StaffMembers.FullName', 'EmployeeName', 'COLUMN'
GO

When this code is executed, the interpreter will look for a column named FullName in the StaffMembers table of the current or selected database. If it finds that column in the table, then it renames it EmployeeName.

 

Home Copyright © 2008-2016, FunctionX, Inc.