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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing name of a column in a table

Status
Not open for further replies.

amunim

Technical User
Aug 4, 2000
3
0
0
NL
could someone help me how to change the name of a column in the table using SQL <br>thanks in advance
 
Standard SQL syntax is<br>select table.field1 AS SomeBetterName<br>from table<br> <p>Malcolm Wynden<br><a href=mailto:wynden@island.dot.net>wynden@island.dot.net</a><br><a href= > </a><br>
 
Try:<br><br>sp_rename 'tablename.fieldname', 'newfieldname', 'COLUMN'
 
Hmmmm - wish you could do that in Oracle :-(<br><br>you have to copy the whole table to somewhere else, then drop the original one and then recreate the table (remembering to change to col name) and repopulate it from copy.....<br><br>table with ten rows? no prob<br><br>table with ten thousand rows? no prob<br><br>table with ten million rows? big pain in the (*&^% <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Thanks for correcting my posting Shyamal - I must have been brain dead on Aug 4.
 
now replies .. starting to be interesting<br><br><br>No other way more simple than copy - drop - recreate new table - repopulate from copy ?<br><br>
 
As Shyamal wrote, you can use sp_rename stored procedure to rename the column name. (Hoping you are using SQL Server as RDBMS)


EXEC sp_rename 'table.[old field name]', '[new field name]', 'COLUMN'


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top