how to rename table in sql server

 252 Total Views,  2 views today

Rename table name in Sql Server
By using sp_rename stored procedure you can rename table name.
Syntax:
exec sp_rename ‘Schema_Name.Old_Table_Name’, ‘New_Table_Name’;

Example:
USE HumanResource
GO
create table employee
(EmpId int NOT NULL,
EmpName varchar(50) NOT NULL
)
GO

insert into employee
(EmpId,EmpName)
values (1,’Solaiman’)
GO

select * from employee
GO

Now rename table from employee to emp by using below syntax:
use HumanResource
GO
exec sp_rename ‘dbo.employee’, ’emp’
GO

use HumanResource
GO
select * from employee
GO

use HumanResource
GO
select * from emp
GO

Leave a Reply

Your email address will not be published. Required fields are marked *