SQL跨数据库更新

SQL跨数据库更新,第1张

UPDATE b

SET b.Com_introduce = a.company_intro --这里改改

FROM australia.dbo.companytest as a, yimingong.dbo.company as b

WHERE

(a.id = 2 AND b.Com_Id = 1) OR

(a.id = 14 AND b.Com_Id = 2) OR

(a.id = 18 AND b.Com_Id = 3) OR

(a.id = 5 AND b.Com_Id = 4) OR

(a.id = 16 AND b.Com_Id = 5) OR

(a.id = 18 AND b.Com_Id = 6) OR

(a.id = 15 AND b.Com_Id = 7) OR

(a.id = 4 AND b.Com_Id = 8) OR

(a.id = 3 AND b.Com_Id = 9) OR

(a.id = 12 AND b.Com_Id = 10) OR

(a.id = 6 AND b.Com_Id = 11) OR

(a.id = 8 AND b.Com_Id = 12) OR

(a.id = 11 AND b.Com_Id = 13) OR

(a.id = 10 AND b.Com_Id = 14) OR

(a.id = 9 AND b.Com_Id = 15) OR

(a.id = 7 AND b.Com_Id = 16) OR

(a.id = 19 AND b.Com_Id = 17) OR

(a.id = 20 AND b.Com_Id = 19) OR

(a.id = 21 AND b.Com_Id = 20) OR

(a.id = 22 AND b.Com_Id = 21)

这样写肯定不行了!

复杂点的方法就是用代码打开所需要的数据,然后读取打开数据库的表

简单点的方法就是创建表链接。以下以2010版为例:

1、外部数据→access→通过创建链接表来链接到数据源,然后选择路径、表……

这样,系统会创建一个与外部数据库中该表同名的链接表,若本地数据有这个名字,系统自动将链接表名+1

2、将当链接表是本地表一样建立更新查询,查询结果可以更新外部数据。当然查询时也可以引用外部数据。一般数据库的前台后台用的就是链接表功能。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9979787.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存