1,背景
项目在上线的时候,经常要求迁移数据,此时就需要执行对应sql同步数据,一般首次同步咋直接全量同步即可,但是对于增量数据则需要执行sql处理了,一般情况下,咋都是直接把增量数据insert语句和update语句捞出来执行即可,但是如果表A中字段1关联了另一个表B的Id值,但是两个环境的Id不一致,写死这个数值在一定程度上具有危险性。
2,使用
注意:针对MySQL数据库,其他类型数据库未实践
select @modelDefId:=id from test01 where code = '001' and enable = 1;
select @mediaModelParentId:=id from test02 where model_def_id = @modelDefId and parent_id =-1 and enable = 1;
INSERT INTO test02
( model_def_id, parent_id, catg_id, catg_name, sort_order, is_leaf, enable, association_key, remark, create_time, create_id, update_time)
VALUES( @modelDefId, @mediaModelParentId, '017', '测试', 1, '1', 1, NULL, NULL, '2024-11-13 20:46:55', NULL, '2024-11-13 20:46:55');