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

I am performing the task of extracting data from both database tables, I have included the following query to achieve it.

The request in the 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 a way to get data from both database tables without using 'Data_00.dbo.yyy' I want to use only yyyinstead.

+3
source share
1 answer

I assume that you are using SQL Server.

Yes, you can create a synonym. Synonyms allow you to specify an abbreviated name for access to various database objects, regardless of whether they are in the same database as the synonym rule or not.

USE Data_01;

CREATE SYNONYM yyy FOR Data_00.dbo.yyy;
+9
source

All Articles