日期:2014-05-19  浏览次数:20484 次

简单的问题
表:   TABLE1

A       B
--------
1       H
2       U
3       P
4       O


A   int   型,是唯一标识

如果我删除A   =   4,   我想在插入另外一条时会从4开始.我如何设置.

------解决方案--------------------
是不是自增列啊,如果不是可以通过
select max(A)+1 from table1来取得@!
------解决方案--------------------
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=4


insert into 表名 select 'ee '

select * from 表名


--此时若要追加id=4的,如下:

set identity_insert 表名 on

insert into 表名(id,txt) select 4, 'ttt '

set identity_insert 表名 off

select * from 表名


drop table 表名
------解决方案--------------------
set identity_insert 表名 on

insert into 表名(id,txt) select 4, 'ttt '

set identity_insert 表名 off

select * from 表名