查找间断SQL的主键
来源:没有验证,呵呵~~
http://topic.csdn.net/u/20071216/10/3e7adb41-5cbc-4e27-9019-79bf8e985a4f.html
方案一、
select MIN(t1.tablesid+1) from tbl_tables t1
where not exists ( select 1 from tbl_tables t2 where t2.tablesid = t1.tablesid +1 )
order by t1.tablesid;
方案二
select MIN(Num) from (select RowNum as Num,A.ID from
(select distinct tablesid as ID from tbl_tables
order by tablesid
) A) where ID - Num>0