Big project includes renaming numerous columns

  • sql 2005 Enterprise: We have a project that will involve adding columns, populating those new columns, creating foreign key constraints and new indexes on said columns, plus renaming many existing columns.

    Its that last bit I'm working on now. I got a copy of Apex's sql refactor, the only problem being that if I have to rename 100 columns, that's a one-at-a-time proposition.

    Then I read that sp_rename renames the associated index, PK or unique constraint. What I'd like to find is a script where I provide the list of tables/columns affected with new name and it generates the dropping, renaming, recreation etc for me. I'm using my own table for this project which includes tables, existing columns, new column names etc so I can generate alter table and other commands dynamically from Tsql.

    sp_rename automatically renames the associated index whenever a PRIMARY KEY or UNIQUE constraint is renamed. If a renamed index is tied to a PRIMARY KEY constraint, the PRIMARY KEY constraint is also automatically renamed by sp_rename.

  • Sounds like fun ! Do you have lots of stored procedures that need to have their column name references changed ?

  • No very few stored procedures but quite a few indexes and foreign key constraints that will have to be modified. So far the apex sql refactor tools just seems to handle one at a time in point/click mode. Perhaps I can capture what it's doing in profiler.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply