Loading ...

Rename column of a table in SQL?

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  data access   » Rename column of a table in SQL?

Rename column of a table in SQL?

Posts under the topic: Rename column of a table in SQL?

Posted: 9/10/2010

Starter 1414  points  Starter
  • Joined on: 12/1/2008
  • Posts: 66

Hello,

 

I want to rename a column of a table....how can i do this?

I know the way to do it through SP

EXEC SP_RENAME
@objname = 'customers.CompanName',
@newname = 'CompanyName',
@objtype = 'COLUMN'


But I couldn't find the way to do it through query.


Does anyone know how to do it?

Thanks.

Sumit


tags sql, column

Posted: 9/10/2010

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

SumitArora said:

user="Sumit Arora"]EXEC SP_RENAME @objname = 'customers.CompanName', @newname = 'CompanyName', @objtype = 'COLUMN'

This is itself a kind of query what type of query you are asking ?


Posted: 9/10/2010

Starter 1414  points  Starter
  • Joined on: 12/1/2008
  • Posts: 66

raghav_khunger said:

user="Raghav Khunger"]This is itself a kind of query what type of query you are asking ?

 

Hello,

By query I mean to say Can i do it by using  DDL i.e by using Alter .

Like

Alter table TableName

 

Thanks,

Sumit Arora


tags Sql, DDl

Posted: 9/10/2010

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

Why do you want to do so ?


Posted: 9/16/2010

Lurker 80  points  Lurker
  • Joined on: 9/14/2010
  • Posts: 8

Posted: 9/16/2010

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

sureshdasari said:

user="Suresh Dasari"]

hi sumit,

 check this url to rename column through sp

http://aspdotnet-suresh.blogspot.com/2010/09/how-to-rename-column-or-table-in-sql.html

Hi Suresh ,

I don't see any single difference what you have written in your blog and what Sumit asked, he too has written sp_rename


Posted: 9/16/2010

Lurker 80  points  Lurker
  • Joined on: 9/14/2010
  • Posts: 8

hi ragav i thought that is query only that's why i have given link thanks for notify me


Posted: 9/16/2010

Professional 8505  points  Professional
  • Joined on: 5/3/2010
  • Posts: 391
  Answered

@Sumit, the safest method is using sp_rename procedure

However, you can see whats happening inside sp_rename by running the followin query:

sp_helptext sp_rename

Therefor, you will be able to discover the logic used in this stored procedure.

This is very good procedure that handles all possible problems that might occur while altering your column_name.

 

Regards,
Hajan


Page 1 of 1 (8 items)