Rename Table Name and Column Name in SQL Server

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

To demonstrate the SQL rename table name and column name, We are going to use the Employees Details table present in our Database. And the data present in the Employee Details Table is:

Database Table records 1

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

SQL Server Rename Table Name

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

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

We are going to use 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 old table

Select Records from Deleted Table Error Message 3

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

Rename Table Name and Column Name in SQL Server 4

SQL Server Rename Column Name

In this SQL rename column name example we will rename column name using the SP_RENAME, 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 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