create table ai(id int identity(1,1),ii int)
insert into ai(ii) select 1
insert into ai(ii) select 2
insert into ai(ii) select 3
select * from ai
delete from ai where ii=3
select * from ai
go
declare @n int
select @n=max(id)+1 from ai
select isnull(min(ids),@n) from (
select (select count(id)+1 from ai where id<a.id) as ids,*
from ai as a) as u
where ids<>id