Query - While Loop

while loop is used for to iterate loop one  by one /
iterate row one by one.

it's an alternative to Cursor.


example,

create Table Test
(
Id int identity(1,1),
Testid uniqueidentifier
)
GO

Declare @i INT=1
 
While (@i<1000)
BEGIN
 
Insert into Test(Testid) values (newid())
Set @i=@i+1
 
END
 GO

































select * from Test

































 While Loop


Simple While loop

Declare @i INT=1



While (@i<=10)



BEGIN



         Print @i



        Set @i=@i+1



 END

While Loop 1


 


Comments