Introduction
In this article, I would like to share how to rename a column name or table name in SQL Server using T-SQL. For that, we have to use sp_rename. sp_rename renames the objects in the current database.
Renaming column name to new column name
The syntax for renaming a column in SQL Server using sp_rename is
SP_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'
Example
SP_RENAME '[DemoWorks].[Sales].[ProductName]' , '[ProductName]', 'COLUMN'
Renaming table name to new table name
The syntax for renaming a table name to a new table name in SQL Server using sp_rename is
SP_RENAME '[OldTableName]' , '[NewTableName]'
Example
SP_RENAME '[DemoWorks].[Sales]' , '[SalesDetails]'
Conclusion
In this simple article, We have discussed renaming columns and tables using sp_rename. I hope this simple tip was very useful. Let’s explore more tips in SQL Server in our upcoming articles. Please share your feedback in the comment section.
Leave a Reply