How to create Sql Synonym or "Alias" for Database Name?

Kevin McKinley picture Kevin McKinley · Jan 14, 2009 · Viewed 37.1k times · Source

I'm using ms sql 2008 and trying to create a database name that references another database. For example 'Dev', 'Test', 'Demo' would be database names that i could reference from my multiple config files, but each name would point to another database such as 'db20080101' or 'db20080114'.

[Edit]Some of the configs are for applications that i control the code and some aren't (ex. MS Reporting service datasource file configs)[/Edit]

It seems that sqlserver only supports synonyms for View,Table,Sproc, or Function. And Alias' are for table and column names.

Is there a way to do this that i missed in the docs? Any one have any suggestions on a workaround?

Answer

SQLMenace picture SQLMenace · Jan 14, 2009

use 3 part notation and alias up to the table, example

select * from tempdb.dbo.sysobjects a
join master.dbo.sysobjects b on a.id = b.id