代码如下:
select * into #temp from Authors
declare @count int;
declare @Au_ID int;select @count = count(*) from #temp
while (@count > 0)
begin
select @Au_ID = max(Au_ID) from #temp ;
select @Au_ID;
delete from Authors where Au_id = @Au_ID;
select @count = count(*) from #temp
end
drop table #temp;

解决方案 »

  1.   

    select * into #temp from Authors
    declare @count int;
    declare @Au_ID int;select @count = count(1) from #temp
    while (@count > 0)
    begin
    select @Au_ID = max(Au_ID) from #temp ;
    select @Au_ID;
    delete from #temp  where Au_id = @Au_ID;   --Authors改#temp 不然死循环
    select @count = count(1) from #temp
    end
    drop table #temp;
      

  2.   

    select * into #temp from Authors
    declare @count int;
    declare @Au_ID int;select @count = count(*) from #temp
    while (@count > 0)
    begin
    select @Au_ID = max(Au_ID) from #temp ;
    select @Au_ID;
             delete from #temp where Au_id = @Au_ID;
    delete from Authors where Au_id = @Au_ID;
    select @count = count(*) from #temp
    end
    drop table #temp;
      

  3.   

    select * into #temp from Authors
    declare @count int
    declare @Au_ID intselect @count = count(*) from #temp
    while (@count > 0)
    begin
    select @Au_ID = max(Au_ID) from #temp
    select @Au_ID
    delete from Authors where Au_id = @Au_ID
             select @count = count(*) from Authors
    end
    drop table #temp
      

  4.   

    我这样做的目的是不想用游标,tntzbzc(华裔大魔王—抗日英雄—抗日要从娃娃抓起)帮我找到原因了,谢谢!