Can you name the SQL column names "middle name" for refactoring purposes?

In a fairly flexible project development, the most problematic for frequent updates is refactoring the table and column names.

When we are working on code that is not high-risk, we can simply add a column or table to the Production database and continue working with real data - not counting the problems with update scripts and updating our TestDb with the latest data from ProductionDb.

Just add a column, add a default value to it. In this case, that's okay. Everything works, no downtime, no hassle of script updates.

Problem

Sometimes we want to reorganize the column names because they didn't respond well to being late.

I was wondering if something like this is possible:

  • Give a (semi) permanent "middle name" to the column (or table)
  • Production server says OldName
  • Development of negotiations with NewName
  • When deploying a new version, we can remove the OldName alias

Result: The column / table name is reorganized without any downtime or script updates.

Is it possible? We are using Entity Framework and SQL Azure.

+3


source to share


2 answers


A bit naive, maybe:

Alternative name for the table:

create view new_table_name as 
select * 
from old_table_name

      

Alternative name for column:



create view new_table_name as 
select x.*, x.old_column_name as new_column_name 
from old_table_name x

      

The following statements are available:

update old_table_name
set old_column_name = value
where key = key_value

update new_table_name
set old_column_name = value
where key = key_value

update new_table_name
set new_column_name = value
where key = key_value

      

See also: How to rename SQL tables column names and not break stuff

+2


source


You will not be able to create an alias for the column or table name, unless you need to update the DB column / table name at some point, you will need to run the script.



While in your code via EF, you can simply update the property name for that column or table and keep the mapping to the original DB name. This means that at least your objects will have a new / better name.

0


source







All Articles