表: TABLE1A   B
--------
1   H
2   U
3   P
4   O
A int 型,是唯一标识如果我删除A = 4, 我想在插入另外一条时会从4开始.我如何设置.

解决方案 »

  1.   

    是不是自增列啊,如果不是可以通过
    select max(A)+1 from table1来取得@!
      

  2.   

    create table 表名(id int identity(1,1), txt varchar(100))
    insert into 表名 select 'aa'
    insert into 表名 select 'bb'
    insert into 表名 select 'cc'
    insert into 表名 select 'dd'
    select * from 表名delete 表名 where id=4insert into 表名 select 'ee'select * from 表名
    --此时若要追加id=4的,如下:set identity_insert 表名 oninsert into 表名(id,txt) select 4,'ttt'set identity_insert 表名 offselect * from 表名
    drop table 表名
      

  3.   

    我找到了用下边的,谢谢各位帮忙GO
    DBCC CHECKIDENT (Table1, RESEED, 4)
    GO
    INSERT INTO TABLE1(B) VALUES('bb')
    SELECT * FROM TABLE1
      

  4.   

    set identity_insert 表名 oninsert into 表名(id,txt) select 4,'ttt'set identity_insert 表名 offselect * from 表名