Home > DeveloperSection > Forums > Rename table name and column name using sql query
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    January-05-2013 5:08 AM

 MSSQL Server MSSQL Server 
Ratings:


 1 Reply(s)
 1064  View(s)
Rate this:
I have a table with the MyTable name and its columns name is
1. sr
2. Name
and i want to rename MyTable into empTable and Name column rename into empName.

MyTable structure as below

Create table MyTable
(
   sr int PRIMARY KEY IDENTITY,
   Name varchar(100)
)

can any one help me?

Thank in advance


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    January-05-2013 6:55 AM

Hi Ankita Pandey

You can use this code
I'm renaming your table and cloumn name with the storeprocedure sp_Rename

sp_Rename 'MyTable', 'empTable'

Now your table name is empTable after renaming your table and now i am going to rename the Name column into empName.
sp_Rename 'empTable.Name', 'empName'
and now you can see your table

Now verify your table

select * from empTable

I hope this resolve your problem

Don't want to miss updates? Please click the below button!

Follow MindStick