Rename Table Name and Column Name in SQL Server

How to Rename Column Names and Table Names is one of the most Frequent Questions in SQL Server forums. In this article, we will show you Rename Table Names and Column Names with an example of each.

To demonstrate the SQL Server rename table name and column name, we will use the Employees Details table present in our Database. And the data present in the Employee Details Table is:

Database records 1

In this SQL Server series of frequent examples, we are going to use the standard stored procedure SP_RENAME to rename the Table name and column name.

SQL Rename Table Name using SP_RENAME

In this example, we will rename the table name using SP_RENAME. The syntax behind this SQL Server approach is as shown below:

SP_RENAME '[Old Table Name]', '[New table Name]'

We are going to use the above specified syntax to rename the EmployeesDetails Table to NewEmployeesDetails

SP_RENAME 'EmployeesDetails', 'NewEmployeDetails'
Rename Table Name and Column Name in SQL Server 2

Now let me try to select records from the old table

Select Records from Deleted Table Error Message 208 3

As you can see from the above screenshot, it is throwing an error. Let me try with a New table name

Employee Records 4

SQL Rename Column Name using SP_RENAME

In this example, we will rename the column name using the SP_RENAME; the syntax behind this approach is as shown below:

SP_RENAME '[Table Name].[Old Column Name]', '[New Column Name]', 'COLUMN'

We are going to use above specified syntax to rename the old column name YearlyIncome to a new name: Annual Income

SP_RENAME 'NewEmployeDetails.YearlyIncome', 'Annual Income', 'COLUMN'

Execute the above sp_rename stored procedure to rename the column query

Messages
--------
Caution: Changing any part of an object name could break scripts and stored procedures.

From the below screenshot, you can see the changed column.

Rename Table Name and Column Name in SQL Server 6
Categories SQL