读书人

简单的有关问题

发布时间: 2012-01-19 00:22:27 作者: rapoo

简单的问题
表: 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 表名

读书人网 >SQL Server

热点推荐