如何在两个不同的数据库中加入两个表?

时间:2021-03-23 15:25:27

I am using SQL Server, I have a Table A in Adb and Table B in Bdb

我使用的是SQL Server,我在Adb中有一个表A,在Bdb中有一个表B.

A Have ID={1,2},Name={Scott,Tiger}
and 
B Have ID={1,2,3},Department={Dept1,Dept2,Dept3}

I want to join both tables with join, my query is similar like this.

我想加入两个表,我的查询是这样的。

SELECT a.ID,a.Name,b.Department FROM Adb.dbo.A as a INNER JOIN Bdb.dbo.B as b
on a.ID=b.ID

But my query always return table with null values. how i can solve this?

但我的查询总是返回具有空值的表。我怎么能解决这个问题?

1 个解决方案

#1


3  

If it is on the same Server just prefix table name with database name and owner.

如果它位于同一服务器上,则只是前缀表名与数据库名和所有者。

 [DatabaseName].[Owner].[TableName] 

#1


3  

If it is on the same Server just prefix table name with database name and owner.

如果它位于同一服务器上,则只是前缀表名与数据库名和所有者。

 [DatabaseName].[Owner].[TableName]