刚刚学SQL有很多不懂请教教—标识列的值有间隔如何修补间隔请问用什么语句来修补呢,请教教我,谢谢

解决方案 »

  1.   

    没必要修补。如果表中ID自动增长的标识中缺少3,那么可以这样插入数据:
    set identity_insert tb on
    insert tb(id,clo) values(3,'jgj')
    set identity_insert tb off
      

  2.   

    一般没必要修补的.相对主键而言,第一不能为NULL,第二不能重复,可以与其它表关联查询就行了.
      

  3.   


    if object_id('test') is not null drop table test
    create table test(id int,father varchar(10),chield varchar(10))
    insert into test 
     select 1 ,'A','A1' union all
     select 2,'A','A2' union all 
     select 3,'A','B' union all 
     select 5,'B','B2' union all
     select 6,'C','G'
    ;
    with liang as
    (
      select *,row_number() over(order by id asc) newid from test
    )update test set test.id=a.newid from liang a where test.id <>a.newid and test.id = a.id
    select * from test
    drop table test
      

  4.   

    with liang as
    (
      select *,row_number() over(order by id asc) newid from test
    )update test set test.id=a.newid from liang a where test.id <>a.newid and test.id = a.id
    select * from test
    drop table test
    这段代码是什么意思啊,我看不懂,能解释一下吗