如上图,computer_idn 有的为null,将null的填入随机数据,但又不能和现有的computer_idn重复

解决方案 »

  1.   

    难度简化,null值有400多个,现有的computer_idn 最小的11213。,所以随机数在1-10000的就可以
      

  2.   


    create table tb(a int,id int)
    insert into tb
    select 1,4560 union all
    select 2,null union all
    select 3,1540 union all
    select 4,4561 union all
    select 5,null
    goupdate tb
    set id = (select cast(ceiling(rand(checksum(newid()))*10000) as  int))
    where id is nullselect *
    from tbdrop table tb
    /*
    a           id
    ----------- -----------
    1           4560
    2           372
    3           1540
    4           4561
    5           7165(5 行受影响)