Using two databases interchangeably with identical structures but different naming conventions

StackOverflow https://stackoverflow.com/questions/19437212

  •  01-07-2022
  •  | 
  •  

Question

At some point in time, we changed the naming schema we use for our database. Every single table name and column name in the database was renamed, but the structure remained identical.

I need to be able to read from both current and legacy tables in my program. Up to now, we simply had a set of large mapping arrays we would use to convert the results on the fly. We've discovered that accessing this array thousands of times in our PHP code to convert every column name in every row of every result is significantly hurting our performance.

What's the best way to solve this? Can it be done from within SQL Server?

Was it helpful?

Solution

I think the two easiest options are:

  • Create a view for every renamed table. The old table name is the new name for your view. The old columns map to the new columns. No application code changes needed.
  • Or, if you have a layer of code to do the mappings you're presumably using an ORM or some other DB abstraction layer. If possible, do your mapping here before the query by adding column alias names, or renaming result set object / array fields.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top