create table t1 ([col] int,[another col] int,[yet another col] int);
create table t2 ([also a col] int,[col] int);
select 'exec sp_rename ''' + QUOTENAME(table_name) + '.' + QUOTENAME(column_name) + ''',''' + replace(column_name,' ','') + ''',''column'''
from information_schema.columns
where table_catalog = 'dmarkovitz'
and column_name like '% %'
exec sp_rename '[t1].[another col]','anothercol','column'
exec sp_rename '[t1].[yet another col]','yetanothercol','column'
exec sp_rename '[t2].[also a col]','alsoacol','column'
select table_name,column_name
from information_schema.columns
where table_catalog = 'dmarkovitz'
and table_name in ('t1','t2')
+------------+---------------+
| table_name | column_name |
+------------+---------------+
| t1 | col |
+------------+---------------+
| t1 | anothercol |
+------------+---------------+
| t1 | yetanothercol |
+------------+---------------+
| t2 | alsoacol |
+------------+---------------+
| t2 | col |
+------------+---------------+
何がうまくいかない?クエリによって文字列が生成されます(実際には、行ごとに1つの文字列が設定された結果セット)。文字列を実行しますか? –
@GordonLinoff試しました。エラー情報が更新されます。 –
100列しかない場合は、それぞれ手動で行うのはなぜですか? –