Introduction
In this blog, I am going to discuss how to rename a table and how to rename column.
In this blog, I am going to discuss how to rename a table and how to rename column.
Background
Most of the time, if we have to rename a table or rename a column we usually drop table and create table again, but with this approach, we lose data. This approach may work in a development environment but in production, we may not want to lose data. So how to achieve this? In SQL Server, we can achieve it easily.
Most of the time, if we have to rename a table or rename a column we usually drop table and create table again, but with this approach, we lose data. This approach may work in a development environment but in production, we may not want to lose data. So how to achieve this? In SQL Server, we can achieve it easily.
Rename table name in SQL Server
Here is the syntax to rename a table.
Here is the syntax to rename a table.
EXEC SP_RENAME 'Old Table Name', 'New Table Name'
Example -
Example -
- EXEC SP_RENAME 'UserLogin', 'User'
Here is the syntax to rename column name.
EXEC SP_RENAME 'Table Name.Old column name', 'New Column Name'
Example -
Example -
- EXEC SP_RENAME '[User].IsActive1', 'IsActive'

Rajesh KumarPosted Jun 13, 2018, 4:25 AM
Nice artical
Diwakar paluruPosted Jul 24, 2017, 3:27 AM
Nice Post, Thank You!