sql 批量更新数据

来源:百度知道 编辑:UC知道 时间:2024/06/18 23:57:41
有两个表A,B
其中A表为基表,B为其子表,他们均有一个type字段
需一SQL将B表中的type(对应A的id)修改为A表的type
一次最多更新1000条数据,可能有几千条数据,请各位帮忙,有加分
1000 是DBA的限制,最多一次可更新1000条数据,如果超过1000,要分多个批次来执行
可以用循环来做吗?数据库为sybase

如果用游标,如何做?

给你写个sqlserver的,其他数据库的话另说

1

update table2 set pwd=table1.ip from table1 inner join table2 on table1.username=table2.username

update a set a.type=b.type from b where a.id=b.id
为什么要一次更新1000条那,如果你硬是想要那样更新那就在加上个条件如下
update a set a.type=b.type from b where a.id=b.id
and a.id in(select top 1000 a.id from a,b where a.id=b.id and a.type!=b.type)

游标好了.

update t1 set type=t2.type from B t1
inner join A t2 on t1.type=t2.id

update B set type = (select type from A where A.id=B.id ) where rownum < 1001