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:
In this series of examples we are going to use the standard stored procedure SP_RENAME to rename SQL Server Table name and column name.
SQL Server Rename Table Name
In this SQL Rename table name example we will rename the table name using the SP_RENAME. Syntax behind this 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'
Now let me try to select records from old table
As you can see from the above screenshot, it is throwing an error. Let me try with New table name
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'
From the below screenshot you can see the changed column
Thank You for Visiting Our Blog