Say I have a table: UltimateTable. It has columns: UltimateColumn1, UltimateColumn2. They should be renamed
UltimateTable_UltimateColumn1
UltimateTable_UltimateColumn2
I believe I can iterate tables with sp_MSForEachTable. How can I rename all the tables in a single database per the example with T-SQL?
I know a lot of people are not a fan of appending table names to column names when an alias will do. Get over it. It’s the company standard.
(j/k I hate it too…)
I agree with Mitch that this is a seriously bad idea and you should fight it to the death. That said, there are easy ways to generate this type of script using the catalog views (not sp_MSForEachTable, which still only gets you the table names, not the column names, anyway).
Run this in one window:
Now copy and paste the output into a new window. Check it over before executing – and test it on a test database first!