Rename Table In SQL Server 2008

In this article we will see how to rename a table using in-built stored procedure.
  • 2208

In this article you will learn how to rename a  database table.

Create Table

use person

create table emp

(

id int,

name varchar(5)

)

insert into emp values(1,'Aman')

insert into emp values(2,'Rahul')

select * from emp

Output:

empTable.jpg

Rename table emp to Employee.

To rename a table, SSMS has system stored procedure sp_rename which modifies the name of an existing table and column name or any other existing database object like view or stored procedure.

Syntax

sp_RENAME 'Table_First', 'Table_Last'

GO

Example:

sp_Rename.jpg

Now Table emp i.e. old name. See it will give an error, because emp table is renamed to Employee.

sp_Rename1.jpg

Now select table Employee.

use person

select * from Employee

Output:

sp_Rename2.jpg

© 2020 DotNetHeaven. All rights reserved.