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.
Author |
Topic |
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2008-01-18 : 15:54:10
|
I have a large number of tables, created by someone else, which have been created with column names containing spaces. I think these can be referenced using back ticks (unless I'm wrong, in which case please correct me), but I don't want to do this, I would rather use underscores.How can I easily rename all the columns in a table, which contain spaces, and replace these with underscores please? |
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-01-18 : 16:10:01
|
You can use sp_rename to rename a column of a table. Here is an example from SQL Server help:EXEC sp_rename 'customers.[contact title]', 'title', 'COLUMN' But make sure, that you may break all the stored proc and functions which refer that column.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-21 : 10:16:52
|
Output of this may help youselect 'EXEC sp_rename '''+table_name+'.['+column_name+']'',''['+column_name+']'','''+replace(column_name,' ','_')+'''' from information_schema.columnswhere column_name like '% %'MadhivananFailing to plan is Planning to fail |
|
|
OldMySQLUser
Constraint Violating Yak Guru
301 Posts |
Posted - 2008-01-21 : 10:28:23
|
Many thanks for that - much appreciated (and to everyone else who replied) |
|
|
|
|
|
|
|