How to synonymize a database name? Within one database instance, I need to restore a set databases into new names. The new names will be suffixed based on the development phases, like: _DEV and _QA. Where:


DBApp_DEV shall access DBGen_DEV, and   
DBApp_QA shall access DBGen_QA.


From DBApp_DEV, I would do this in an SP:

select Col1 from DBGen_DEV.dbo.TableName


However, from DBApp_QA I would have do this in the same SP:

select Col1 from DBGen_QA.dbo.TableName


Now, how can I synonymize the database name in that SP?
OK, I managed to solve this by creating a Synonym in DBApp_DEV:

CREATE SYNONYM GenTableName FOR DBGen_DEV.dbo.TableName


And in DBApp_QA, the Synonym would be:

CREATE SYNONYM GenTableName FOR DBGen_QA.dbo.TableName


This way, I can maintain the exact same query in my SP that exists in both DBApp_* databases:

select Col1 from GenTableName