i am trying to change column names in a bunch of tables.
why is this not right
is there any sp that i can use as i have to change this in a lot of tables across two databases
Alter Table Answers
Change Product NewProduct varchar(35)
i am trying to change column names in a bunch of tables.
why is this not right
is there any sp that i can use as i have to change this in a lot of tables across two databases
Alter Table Answers
Change Product NewProduct varchar(35)
change column names
Dances With Data
JavanehA
EXEC sp_rename 'Answers2.[Product]', 'NewProduct1', 'COLUMNA' GO
EXEC sp_rename 'Answers3.[Product]', 'NewProduct2', 'COLUMNB' GO
EXEC sp_rename 'Answers4.[Product]', 'NewProduct3', 'COLUMNC' GO
NorthSeattle
kitchen
select
'exec sp_rename ''' + obj.name + '.[' + col.name + ']'', ' + ' ''NewProduct'' go'from
syscolumns coljoin
sysobjects obj on col.id = obj.idwhere
col.name = 'Product'-------------------------------------------------------------------------
That will output a load of dynamic SQL. Now copy and paste into Query Analyser or the query execution window, test and execute.
For more SQL Server tips, check out my blog:
http://blogs.claritycon.com/blogs/the_englishman/default.aspx
HTH
Janga
istanbul 05
This works.
EXEC
sp_rename 'Answers2.[Product]', 'NewProduct', 'COLUMN'now how do i do multiple columns.......
if anyone can figure faster
Daniel Upton
You may need to alter the query to:
:
select
'exec sp_rename ''' + obj.name + '.[' + col.name + ']'', ' + ' ''NewProduct'' go'from
syscolumns coljoin
sysobjects obj on col.id = obj.idwhere
col.name = 'Product' and obj.[type] = 'U'-------------------------------------------------------------------------
To ensure only tables are returned from sysobjects