sp_rename – Rename a column or table in MS SQL Server

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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Website Built with WordPress.com.

Up ↑

%d bloggers like this: