Skip to content

How to Rename a Column in SQL Server

Category
Databases
Covers
SQL Server
On this page

Database design is the organization of data. A good database design makes it successful. Its recommended to follow a good pattern for the table names and their columns. In some cases, you may be required to rename a column name of the table to maintain a proper architecture and naming pattern. The sp_rename stored procedure is used to rename a column name in a table in MSSQL server database.

Syntax:

The syntax of the sp_rename stored procedure is:

sp_rename 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'
Caution: Changing any part of an object name could break scripts and stored procedures. Make sure to update all the required scripts and stored procedures with updated names.

Rename a Column in SQL Server

For example, I have a table named Accounts in the MSSQL server database. This table contains a column named “cust_id”. For some reason, we need to rename this column to “customer_id”. See below screenshot:

Open query windows and execute the following query. Here Test_dbis the database name.

USE Test_db
GO

sp_rename 'Accounts.cust_id', 'customer_id' , 'COLUMN'
GO 

This may show you a warning message with the result, But this will rename the column name successfully. Checked the table structure again, and I found that the column is updated as required.

Rename table column in SQL Server

Conclusion

This tutorial helped you to rename a table column name in the SQL Server database.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top