SQL Server: RENAME Column or Table Name
You can rename table name, column name of an existing table, index name by using the system stored procedure sp_rename
.
EXEC sp_rename 'old_name', 'new_name' [, 'object_type'];
Rename Table: To rename a table, 'old_name' must be an existing table name or schema.table
.
Rename Column: To rename a column in a table, 'old_name' must be in the form of table.column
or schema.table.column
.
Rename Index: To rename an index, 'old_name' must be in the form table.index
or schema.table.index
.
Rename Constraints: To rename a constraint, 'old_name' must be in the form schema.constraint
.
The following renames Address
column of the Employee
table to TempAddress
.
EXEC sp_rename 'Employee.Address', 'TempAddress';
The following renames Employee
table to Consultant
table.
EXEC sp_rename 'Employee', 'Consultant';
You can specify the object type to indicate whether it is a column, index, database, etc.
EXEC sp_rename 'Employee.Address', 'TempAddress', 'COLUMN';
Note that the new column name should not prepend table name.
Learn more about sp_rename stored procedure.
Rename Table and Columns Using SSMS:
Open SSMS and expand the database folder.
Select and right-click on a table or a column you want to rename and click Rename. Enter a new name by over writing on existing name.
Go to the file menu and click Save.