The sp_rename stored procedure is used to rename a column name in a table in MSSQL server database.
Here is the syntax of the sp_rename stored procedure.
sp_rename 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'
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 MyDB is the database name.
sp_rename 'Account.cust_id', 'customer_id' , 'COLUMN'
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 column is updated as per required.