chetan1539
chetan1539

Reputation: 121

How to query a table from different databases without using alias of database?

I am doing task of retrieving the data from both database tables,I included following query to achieve it.

Query in stored procedure:

--Some query here...
LEFT OUTER JOIN     aaa c 
ON                  l.IDNo      = c.LogonIDNo
INNER JOIN          Data_00.dbo.yyy A
ON                  C.MacCusNo  = A.Cus_no
LEFT OUTER JOIN     abc T 
ON                  A.xyz       = T.bbb

Tables:

aaa : table of database Data_01
yyy : table of database Data_00

Is there any way to retrieve the data from both the database tables without using 'Data_00.dbo.yyy' I want to use only yyy instead of it.

Upvotes: 3

Views: 447

Answers (1)

weenoid
weenoid

Reputation: 1186

I'll assume you're using SQL Server.

Yes, you can create a synonym. Synonyms allow you to specify a shorthand name for accessing various database objects, whether they reside in the same database as the synonym rule or not.

USE Data_01;

CREATE SYNONYM yyy FOR Data_00.dbo.yyy;

Upvotes: 9

Related Questions