Mysql迁移到DM,自增种子问题批量处理

源库是MYSQL,如果源库迁移到DM时,源端数据库没有停止业务系统,往往会有数据写入,此时将表结构的自增列迁移到DM以后,种子的值写入DM后,后续可能存在自增列数据冲突的问题,因此需要在DM手动将种子的基础值增加一定数量【一般还是建议将源端数据库停止再写入】。

drop table if exists test_table_1;
drop table if exists test_table_2;
drop table if exists test_table_3;
drop table if exists test_table_4;
create table test_table_1(tabid1 int identity(3,2) primary key, name varchar(32));
create table test_table_2(tabid2 int identity(30,3) primary key, name varchar(32));
create table test_table_3(tabid3 int  primary key, name varchar(32));
create table test_table_4(tabid4 int identity(300,3) primary key, name varchar(32));
declare
        v_seed       int;
        v_incr       int;
        v_select_sql varchar2(800);
        v_drop_sql   varchar2(800);
        v_create_sql varchar2(800);
begin
        for temp_row in
        (
                select
                        b.table_name                      ,
                        a.name col_name                   ,
                        ident_seed(b.table_name) temp_seed,
                        ident_incr(b.table_name) temp_inc
                from
                        sys.syscolumns a,
                        user_tables b    ,
                        user_objects c
                where
                        a.info2 & 0x01 = 0x01
                    and a.id           =c.object_id
                    and c.object_name  = b.table_name
        )
        loop
                v_drop_sql:='alter table test_table_name drop identity';
                v_drop_sql:=replace(v_drop_sql, 'test_table_name', temp_row.table_name);
                print v_drop_sql;
                execute immediate v_drop_sql;
                v_create_sql:= q'*alter table test_table_name add column test_column_name identity(test_seed_id,test_inc_value)*';
                v_create_sql:=replace(v_create_sql, 'test_table_name', temp_row.table_name);
                v_create_sql:=replace(v_create_sql, 'test_column_name', temp_row.col_name);
                v_create_sql:=replace(v_create_sql, 'test_seed_id', temp_row.temp_seed+10000);
                v_create_sql:=replace(v_create_sql, 'test_inc_value', temp_row.temp_inc);
                print v_create_sql;
                execute immediate v_create_sql;
                print '处理完一个';
        end loop;
end;
/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值