RENAME TABLE NAME AND COLUMN NAME USING SQL QUERY

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
 1360  View(s)
Ratings:
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
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Rename table name and column name using sql query

    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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!