碰到这个需求,不会
假如有两个数据库DB1 DB2
DB1有张user表
DB2有张vip表
user表uid name isNew
1 a true
2 b true
3 c true
4 d false
....vip表vid uid isGold
1 3 true
2 1 false
3 2 true
3 4 true
....现在想找出新用户(isNew)并且是黄金(isGold)VIP用户的name
假如有两个数据库DB1 DB2
DB1有张user表
DB2有张vip表
user表uid name isNew
1 a true
2 b true
3 c true
4 d false
....vip表vid uid isGold
1 3 true
2 1 false
3 2 true
3 4 true
....现在想找出新用户(isNew)并且是黄金(isGold)VIP用户的name
where a.isNew='true' and b.isGold='true'
select a.* from DB1.dbo.[user] a,DB2.dbo.vip b
where a.isNew='true' and b.isGold='true'
select a.name
from DB1..[user] a , DB2..[vip] b
where a.uid =b.uid and a.isNew='true' and b.isGold='true'
不会。
select a.name
from DB1.dbo.[user] a,DB2.dbo.[vip] b
where a.uid = b.uid and a.isNew='true' and b.isGold='true'
select a.* from DB1.dbo.[user] a,DB2.dbo.vip b
where a.uid=b.uid and a.isNew='true' and b.isGold='true'
--在uid字段建立索引
--50w数据不算多,没有问题
--刚才写错了,少了个连接条件,抱歉。
left join DB2.dbo.vip tvip on tuser.uid = tvip.uid
where tuser.isNew='true' and tvip.isGold='true'如果数据很多,比如50W条,跨数据库查询会不会存在严重问题.这个还好,数据不是很多,才50W
a.name
from
DB1..[user] a , DB2..[vip] b
where
a.uid =b.uid and a.isNew='true' and b.isGold='true'