I want to rename a column in a table. I see two approaches
Use
sp_rename()
and modify stored procedures to refer to new name.Create new column, copy data from old column to new column, modify stored procedure etc. to refer to new column, eventually drop old column.
We can't use #1 as renaming column might leave stored procedures broken and we cannot afford any downtime.
If we go with #2, there is possibility that both old and new columns would co-exist for sometime after the data is copied over from old to new column but before the stored procedures deployed to use the new column.
Is there any way to keep the new column in sync with any updates/insert/deletes done to old column?
- Can the
AFTER
triggers help here? But triggers usually increase the transaction time, so may not be a favorable solution. - Can I replicate data between two columns of the same table?
- Any other possible solutions?
Also does sp_rename() cleanly updates all the references to the column - like stored procedures, functions, indexes etc?