在数据库 A中有个表 tb_dep_a 字段A1,B1
在数据库 B中有个表 tb_dep_b 字段A1,B1
现在想 把A的数据更新到B如果在同一个库中
可以这样写
update tb_dep_b set tb_dep_b.B1=b.b1
from tb_dep_a b
where tb_dep_b.a1=b.a1
但是跨越了数据库 这样写update b.dbo.tb_dep_b set tb_dep_b.B1=b.b1
from a.dbo.tb_dep_a b
where tb_dep_b.a1=b.a1出现了错误
在数据库 B中有个表 tb_dep_b 字段A1,B1
现在想 把A的数据更新到B如果在同一个库中
可以这样写
update tb_dep_b set tb_dep_b.B1=b.b1
from tb_dep_a b
where tb_dep_b.a1=b.a1
但是跨越了数据库 这样写update b.dbo.tb_dep_b set tb_dep_b.B1=b.b1
from a.dbo.tb_dep_a b
where tb_dep_b.a1=b.a1出现了错误
update b set b.b1=a.b1
from db1.dbo.tb_dep_b b left join db2.dbo.tb_dep_a a on a.a1=b.a1
如果系统消息提示:“对象名 '(查询的数据表)' 无效。”
修改为:“[数据库名].[dbo].[表名]”
from dbo.tb_dep_a
where dbo.tb_dep_b.a1=dbo.tb_dep_a.a1
update a set a.B1=b.b1
from b.dbo.tb_dep_b a inner join a.dbo.tb_dep_a b
on a.a1=b.a1
from
(select a.a1 as 新A1,A.B1 AS 新b1 from a.dbo.tb_dep_a )
c
where a1=c.新a1这个方法解决了问题
--这样看起来比较好点
update
a
set
B1=c.新b1
from
b.dbo.tb_dep_b a1,
(select a.a1 as 新A1,A.B1 AS 新b1 from a.dbo.tb_dep_a )c
where
a.a1=c.新a1
b.dbo.tb_dep_b
set
B1=c.新b1
from
(select a.a1 as 新A1,A.B1 AS 新b1 from a.dbo.tb_dep_a )c
where a1=c.新a1
from a.dbo.tb_dep_a..b where tb_dep_b.a1=b.a1这样就行了
from a..tb_dep_a b where tb_dep_b.a1=b.a1