Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change column name in T-SQL

Status
Not open for further replies.

agoeddeke

Programmer
Jul 23, 2002
201
US
Hello,

Is there any way to change a column name in T-SQL using ALTER TABLE or something?

I'd like to rename a column yet still keep it's same ordinal position.

Thanks,
Andy
 
This shows you how to change a column

CREATE TABLE doc_exa ( column_a INT)
GO
ALTER TABLE doc_exa ALTER COLUMN column_a NVARCHAR(20) NOT NULL
GO
EXEC sp_help doc_exa
GO
DROP TABLE doc_exa
GO


 
Probably the easiest way of renaming an object is to use sp_rename. For a column you would use some thing like this.

EXEC sp_rename 'ColumnName', 'NewName', 'COLUMN'

 
Thanks furbank,

SP_RENAME does the trick.

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top