如果SQL数据库中A表和B表通过key关联,那么如何进行批量更新数据呢?下面就将为您介绍这种批量更新数据的SQL语句写法,供您参考,如果您在SQL批量更新数据方面遇到过问题,不妨一看,相信对您会有所启迪。
A,B表通过key关联的批量更新数据方法:
批量修改:{
update A
set A.qcye=B.qcye
from B
where A.kmdm=B.kmdm
and A.fmonth=B.fmonth
and A.fmonth=0
}
修改之后的查询,结果正确,OK
{
select * from A
where fmonth=0 and qcye<>0
and kmdm like '1606%' and len(kmdm)=10 order by kmdm
select * from B where fmonth=0 and qcye<>0
and kmdm like '1606%' and len(kmdm)=10 order by kmdm
}
A,B表通过key关联的批量更新数据方法:
批量修改:{
update A
set A.qcye=B.qcye
from B
where A.kmdm=B.kmdm
and A.fmonth=B.fmonth
and A.fmonth=0
}
修改之后的查询,结果正确,OK
{
select * from A
where fmonth=0 and qcye<>0
and kmdm like '1606%' and len(kmdm)=10 order by kmdm
select * from B where fmonth=0 and qcye<>0
and kmdm like '1606%' and len(kmdm)=10 order by kmdm
}