--臨時表 declare @t table(ID int) declare @i int select @i=1 while @i<=50000 begin insert @t select @i set @i=@i+1 end select ID from tb t where not exists(select 1 from @t where id=t.id)
SELECT TOP 50000 id = IDENTITY(int, 1, 1) INTO # FROM syscolumns a, syscolumns b ,syscolumns c select id from tb t where not exists(select 1 from # where id=t.id)
select number,TB.id from Master..spt_vlues A left join TB on A.number = TB.id ID 为null的就是没有的。
Master..spt_vlues 只能记录2048条
with cte as (select row_number() over(order by a.id) num from sysobjects a,sysobjects b,sysobjects c) select num from cte a where num<=50000 and not exists (select 1 from tb where num=id )
declare @t table(ID int)
declare @i int
select @i=1
while @i<=50000
begin
insert @t select @i
set @i=@i+1
end
select ID from tb t
where not exists(select 1 from @t where id=t.id)
select
id
from
tb t
where
not exists(select 1 from # where id=t.id)
from Master..spt_vlues A
left join TB on A.number = TB.id
ID 为null的就是没有的。
with cte as
(select row_number() over(order by a.id) num from sysobjects a,sysobjects b,sysobjects c)
select num from cte a where num<=50000 and not exists
(select 1 from tb where num=id )