Rename Table Name and Column Name in SQL Server

How to Rename Column Name in Sql Server, or How to rename Table Name in Sql Server is one of the most Frequent Question 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 [SQL Test] Database. And the data present in the Employee Details Table is:

Rename Table Name and Column Name in SQL Server 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:

-- Syntax for SQL Server rename Table Name is: 
SP_RENAME '[Old Table Name]', '[New table Name]'

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

-- SQL Server rename Table Name is: 
USE [SQLTEST]
GO
SP_RENAME 'EmployeesDetails', 'NewEmployeDetails'
Rename Table Name and Column Name in SQL Server 2

Now let me try to select records from old table

Rename Table Name and Column Name in SQL Server 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:

-- Syntax for SQL Server rename Column Name is: 
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

-- SQL Server Rename Column Name query is: 
USE [SQLTEST]
GO
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