我在一个表里,一有字段ID,
ID
1
2
4
6
88我现在要的是,以后添加ID时把ID里没有的顺序值添加上去
如3在这里面现在没有,我添加下一条语句时,就添加3
3添加了,那么下一条记录的ID就是5........如何做?谢谢
ID
1
2
4
6
88我现在要的是,以后添加ID时把ID里没有的顺序值添加上去
如3在这里面现在没有,我添加下一条语句时,就添加3
3添加了,那么下一条记录的ID就是5........如何做?谢谢
insert into tb
select 1 union all
select 2 union all
select 4 union all
select 6 union all
select 88
select top 1000 id=identity(int,1,1) into tmp from syscolumns a,syscolumns b
insert into tb
select min(id) from #t where id not in (select id from tb)select * from tb order by id/*
id
---
1
2
3
4
6
88
*/drop table tb,tmp