Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Updating column names in QA

Author  Topic 

KidSQL
Yak Posting Veteran

88 Posts

Posted - 2005-04-27 : 17:02:56
I was just wondering how I could go about changing the names of columns in some of my tables using Query Analyzer. I have been doing this in Enterprise Manager, which is lovely, but it's not very practical when I have dozens of column names to deal with.

I was thinking I would have to use somethign like

update mytable set mytable.ColumnName(oldcolumn) = "New_Column"

but this doesn't seem to work. Any ideas would be greatly appreciated.

Thanks!

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-04-27 : 17:11:56
Use sp_rename:

create table junk (col1 int)
GO
select * from junk
go
sp_rename 'junk.col1', 'colA', 'column'
go
select * from junk
GO
drop table junk

Be One with the Optimizer
TG
Go to Top of Page

KidSQL
Yak Posting Veteran

88 Posts

Posted - 2005-04-27 : 17:17:55
Thanks, TG (as per usual)!
Go to Top of Page
   

- Advertisement -