Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 232
Kevin McKinley Avatar asked Jan 14 '09 18:01

Kevin McKinley


People also ask

How do I create a database alias in SQL?

Go to the Database you wish to create Alias, Create an Alias Folders table with the preferred design, Go to unique IDs's table and check the last code sequence for the table created. For example, if the last code is 10, then update it to 11.

Can you alias a database name?

Each database can have only one DB alias. Each DB alias name must be unique.

Can I create synonym for database in SQL Server?

Use SQL Server Management Studio In Object Explorer, expand the database where you want to create your new view. Right-click the Synonyms folder, then select New Synonym.... In the Add Synonym dialog box, enter the following information. Type the new name you will use for this object.

How do I create Synonyms in SQL?

SQL Server CREATE SYNONYM statement syntax First, specify the target object that you want to assign a synonym in the FOR clause. Second, provide the name of the synonym after the CREATE SYNONYM keywords.


1 Answers

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 
like image 88
SQLMenace Avatar answered Sep 22 '22 06:09

SQLMenace