若有错漏,请指正或补充
---------------------------------------------------------------
大家交流一下,如果有空缺会自己填上,自动递增。
select (case when isnull((select min(id) as id from 物品 where 编号=1),0)=0 then 1 else isnull(min(编号),0)+1 end) as ID from 物品 a where not exists(select 1 from 物品 where 编号=a.编号+1)