2

I need to change the name for a few databases, however the databases are used by a lot of applications managed by several different teams. It would take some time for all the applications to finish changing connections and database name references. Is there a way to allow the change to be done seamlessly? Was looking at synonyms to temporarily allow references to the renamed database but unfortunately it is only for database level.

JieLong
  • 315
  • 1
  • 9

1 Answers1

7

Create an "alias" database with the name you want to use. Create synonyms for the objects by querying the system tables to create a simple script, here for example for user tables.

select 
  'Create Synonym '
   +quotename(object_schema_name(id, db_id()))+'.'
   +quotename(o.name)+
   ' For [SourceDB].'
   +quotename(object_schema_name(id, db_id()))+'.'
   +quotename(o.name)+';' 
from sysobjects o where type = 'U'
Stephen Morris - Mo64
  • 4,656
  • 1
  • 10
  • 18