declare @i int
select @i=max(id) from yourtable
exec('select top '+@i+' id=identity(int,1,1) into tmp from syscolumns a,syscolumns b')select t.id
from tmp t
where not exists(select 1 from yourtable where id=t.id)
select @i=max(id) from yourtable
exec('select top '+@i+' id=identity(int,1,1) into tmp from syscolumns a,syscolumns b')select t.id
from tmp t
where not exists(select 1 from yourtable where id=t.id)
select count(id) from TableName看这两个值是否相等
你自己说这样的啊,如果是'0000000N'这样当然也能解决做些变化:declare @i int
select @i=max(id) from yourtable
exec('select top '+@i+' id=identity(int,1,1),nid='00000000' into tmp from syscolumns a,syscolumns b')update tmp set nid=right(nid+cast(id as varchar(10)),8)select t.nid
from tmp t
where not exists(select 1 from yourtable where id=t.nid)
declare @tmp table(nid varchar(8) primary key)select @i=max(id) from yourtable
while @i>0
begin
insert @tmp select right('00000000'+cast(@i as varchar(10)),8)
set @i=@i-1
endselect t.id
from @tmp t
where not exists(select 1 from yourtable where id=t.id)