-- 最小未用的idselect min(id)+1 from tb a
where not exists(
select * from tb where id=a.id+1)
where not exists(
select * from tb where id=a.id+1)
解决方案 »
- 请教一个问题: image 对象专门存在一个表 还是 和其他字段放一个表?
- 一个比较复杂的触发器写法
- 问大家一个小问题,很急,大家帮忙,在线等
- 请教一个修改数据的问题
- 我想比较两个数据库中的表的结构怎办?
- 存储过程里得LIKE的语法是怎么写的?
- ☆☆☆求一条SQL语句☆☆☆
- 请问如果有同事远程改了我SQL SERVER中的一个表中的一个数据,我能否查看到他改的是哪张表?
- 表的ID是主键自增,日期为取当前时间,这样的话用时间为记录集排序效率是否和用ID排序一样?
- 帮帮我好吗.急.........
- 我把uniqueidentifier改为varchar长度为36,会不会出现问题呢?
- 请问一个SQL函数
insert into @t select 1
insert into @t select 2
insert into @t select 4
insert into @t select 6
insert into @t select 7select
min(id)+1
from
(select id=0 from @t where not exists(select 1 from @t where id=1)
union
select id from @t a where exists(select 1 from @t where id>a.id) and not exists(select 1 from @t where id=a.id+1)
union
select max(id) from @t) a
insert into @t select 1
insert into @t select 2
insert into @t select 4
insert into @t select 6
insert into @t select 7select
min(id)+1
from
(select id=0 from @t where not exists(select 1 from @t where id=1)
union
select id from @t a where not exists(select 1 from @t where id=a.id+1)) a
insert into @t select 1
insert into @t select 2
insert into @t select 4
insert into @t select 6
insert into @t select 7
select min(id+1) from @t a where not exists(select 1 from @t where id=a.id+1)