Bing Yee程序人生

关注互联网产品技术学习,应用开发~

SQL 两个表关联更新(Update)写法

2011/7/22 17:27:58 类别:数据库
摘要:整理多表数据关联时用到此SQL 语法老是报错,查询一下,备注一下以备不时之需

 这里就直接贴代码了

--更新关联字段 这里用的LIKE关联 相信如果是=或者别的条件,你一定可以写出来噢!
Update PostCode Set PID=Area_Base.ID From Area_Base,PostCode Where  PostCode.XianName like Area_Base.Area_ShortName+'%' ANd Area_Base.Area_Level=3 

 再写一个多字段更新的,就直接从网上贴来,不解释了

update customers a  
   set    (city_name,customer_type)=(select b.city_name,b.customer_type 
                                     from   tmp_cust_city b 
                                     where  b.customer_id=a.customer_id)
   where  exists (select 1 
                  from   tmp_cust_city b
                  where  b.customer_id=a.customer_id
                 )

 如果还有不明白的就Q我吧,或者在评论中留言~

4465次阅读  标签:关联更新,多表
下一篇:MSDE是什么?
上一篇:什么是ER图?

共11条评论

home(1楼)-2016/11/4 8:59:34
审核中

home(2楼)-2016/11/23 16:40:12
审核中

Edycrurse(3楼)-2020/4/22 18:58:30
审核中

发表评论

文章分类


友情链接