在做数据迁移的时候,最蛋疼的就是数据之间的外键关联.这种硬关联在来回的导数据的时候也特别的让人纠结.

我们的系统中,企业基本信息(BASE_QYJBXX)和人员基本信息(BASE_RYJBXX)的关联是通过企业人员关系表(BASE_QYRYGXB)来关联的.

BASE开头的表示我们的基础数据,企业在做业务的时候都会把BASE表给的基础数据,拷贝到过程表(PROCESS_*)里,来让客户做修改.

最后通过审批以后,过程表(PROCESS_*)中的数据会回写到BASE_*表中.

insert
into
PROCESS_QYRYGXB
(CREATE_DATE,ID,QYJBXX_ID,RYID,RYLX,UPDATE_DATE,UU_ID,liushuihao) select
BASE_QYRYGXB.CREATE_DATE,
BASE_QYRYGXB.ID,
PROCESS_QYJBXX.id,
PROCESS_RYJBXX.id,
BASE_QYRYGXB.RYLX,
BASE_QYRYGXB.UPDATE_DATE,
BASE_QYRYGXB.ID,
'0014130619000263'
from
BASE_QYRYGXB,PROCESS_RYJBXX,PROCESS_QYJBXX
where
(
rylx='QYRYFXB004'
or rylx='QYRYFXB002'
or rylx='QYRYFXB003'
or rylx='QYRYFXB010'
or rylx='QYRYFXB001'
)
and qyjbxx_id=21421737 and BASE_QYRYGXB.Qyjbxx_Id=PROCESS_QYJBXX.UU_ID and BASE_QYRYGXB.RYID = PROCESS_RYJBXX.Uu_Id




insert
into
PROCESS_QYRYGXB
(CREATE_DATE,ID,QYJBXX_ID,RYID,RYLX,UPDATE_DATE,UU_ID,liushuihao) select
BASE_QYRYGXB.CREATE_DATE,
BASE_QYRYGXB.ID,
PROCESS_QYJBXX.id,
PROCESS_RYJBXX.id,
BASE_QYRYGXB.RYLX,
BASE_QYRYGXB.UPDATE_DATE,
BASE_QYRYGXB.ID,
'0014130619000263'
from
BASE_QYRYGXB,PROCESS_RYJBXX,PROCESS_QYJBXX
where
(
rylx='QYRYFXB004'
or rylx='QYRYFXB002'
or rylx='QYRYFXB003'
or rylx='QYRYFXB010'
or rylx='QYRYFXB001'
)
and qyjbxx_id=3322 and BASE_QYRYGXB.Qyjbxx_Id=PROCESS_QYJBXX.UU_ID and BASE_QYRYGXB.RYID = PROCESS_RYJBXX.Uu_Id and PROCESS_QYJBXX.Liushuihao='20130607145133' and

PROCESS_RYJBXX.Liushuihao='0014130619000263'