update basplumain set dptid=1
delete from basdept where id!=1
insert into basdept (dptno,dptname)
select dptno,dptname from lhflm
update basdept set pid=b.id from basdept a,(select a.dptno,a.dptname,b.id
from lhflm a
left join basdept b on a.pid=b.dptno) b
where a.dptno=b.dptno and b.id is not null
原文地址:http://www.cnblogs.com/nlg3413/p/3946540.html