如何让一个字段值从8321256588开始自增,如:我有一张表table1,里面有一个字段CSCustomerID,但是它是空的,现在我想赋予它一批值,我希望此表中这个字段字段的值是从321256588开始自增,这种情况我该怎么办?请高手指教,谢谢.

解决方案 »

  1.   


    create table tb(id bigint identity(321256588,1),ic int)
    insert into tb
    select 1 union all
    select 2
    goselect *
    from tbdrop table tb/*************id                   ic
    -------------------- -----------
    321256588            1
    321256589            2(2 行受影响)
      

  2.   

    先增加一条记录
    --注意必须指定种子列的列名,如下例中的id必须要列出
    SET IDENTITY_INSERT tb ON
    INSERT tb(id,col) VALUES(321256588,11)
    SET IDENTITY_INSERT tb OFF 再删除此条记录,后面新添加记录时自动从321256588开始
      

  3.   


    create table tb(id bigint identity(1,1),ic int)
    insert into tb
    select 1 union all
    select 2
    goselect *
    from tb/*
    id                   ic
    -------------------- -----------
    1                    1
    2                    2
    */set identity_insert tb on
    insert into tb(id,ic) values(321256588,3)
    set identity_insert tb offselect *
    from tb/*
    id                   ic
    -------------------- -----------
    1                    1
    2                    2
    321256588            3
    */delete from tb where id = 321256588select *
    from tb/*
    id                   ic
    -------------------- -----------
    1                    1
    2                    2
    */insert into tb
    select 5select *
    from tb/*
    id                   ic
    -------------------- -----------
    1                    1
    2                    2
    321256589            5
    */drop table tb