???? ID: 111401 - ????? ???????: 03 ?????? 2010 - ??????: 4.0

??? SQL Server Transact SQL ?? ????? ?? ??? ???? ??? ??? ?????? ?? ?????? ?? iterate ???? ????

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.

?? ????? ??

??? ?? ??????? ???? | ??? ?? ??????? ????

??????

?? ???? ????? ???? ?? ?? ??????? ??????? ??? ????? ????? ?? ???????? ?????????, ??????, ?? Transact SQL ??? ??? ????? like FETCH NEXT ????? ???????? ???? ?? ??? ?? ???? ????

?????? ?? ???? ??? ?? Iterate ???? ?? ??? Transact-SQL ??? ?? ????? ????

??? ??????? Transact SQL ??? ?? ????? ?? ??? ???? ??? ??? ?????? ?? ?????? ?? iterate ???? ?? ??? ????? ?? ???? ????

?? ?????? ?? ?? ?????temp????????? ?? ???? ?? ??? ???? ?? "????????" ?? ?????? ??? ??? ????? ?? ??? "cursoring." ?? ??? ?? ???? ?? ??? ??? ????? ???? ?????? ?? ???::
/********** example 1 **********/ 

declare @au_id char( 11 )

set rowcount 0
select * into #mytemp from authors

set rowcount 1

select @au_id = au_id from #mytemp

while @@rowcount <> 0
begin
    set rowcount 0
    select * from #mytemp where au_id = @au_id
    delete #mytemp where au_id = @au_id

    set rowcount 1
    select @au_id = au_id from #mytemp<BR/>
end
set rowcount 0
				

??? ????? ???? ?? ????? ???? ?? ??? ??????????????? "walk" ?????? ?? ?????? ?? ?? ??? ?? ??? ??? ?? ???? catches ????? ??? ???????? ????????? ?? ???????? ?? ???, ??????? ???? ?? ??? ?? ?????? ??? ?? ????? ?????????? ?????? ??? ??????? ???? ?? ??? ?? ??????? ?????? ?? ???? ?? ?????? ?? ????????? ???? ?????? ?? ???::
/********** example 2 **********/ 

declare @au_id char( 11 )

select @au_id = min( au_id ) from authors

while @au_id is not null
begin
    select * from authors where au_id = @au_id
    select @au_id = min( au_id ) from authors where au_id > @au_id
end
				
???:: 1 ?? 2 ????? ?????? ???? ?? ?? ???? ????? ?????????? ????? ?????? ??? ???????? ?????? ?? ??? ????? ??? ??? ?????? ???, ??? ????? ?????????? ????? ?? ???? ??? ??? ?????? ??, ?? ?? ??????? ?? ???? ???temp?? ???? ?? ????? ????? ?? ????? ???? ?? ??? ?????? ??????? ?????? ?? ???::
/********** example 3 **********/ 

set rowcount 0
select NULL mykey, * into #mytemp from authors

set rowcount 1
update #mytemp set mykey = 1

while @@rowcount > 0
begin
    set rowcount 0
    select * from #mytemp where mykey = 1
    delete #mytemp where mykey = 1
    set rowcount 1
    update #mytemp set mykey = 1
end
set rowcount 0
				



???? ???? ???? ??:
  • Microsoft SQL Server 2000 Standard Edition
  • Microsoft SQL Server 4.21a Standard Edition
  • Microsoft SQL Server 6.0 Standard Edition
  • Microsoft SQL Server 6.5 Standard Edition
  • Microsoft SQL Server 7.0 Standard Edition
  • Microsoft SQL Server 2005 Standard Edition
  • Microsoft SQL Server 2005 Developer Edition
  • Microsoft SQL Server 2005 Enterprise Edition
  • Microsoft SQL Server 2005 Express Edition
  • Microsoft SQL Server 2005 Workgroup Edition
??????: 
kbhowtomaster kbmt KB111401 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:111401  (http://support.microsoft.com/kb/111401/en-us/ )