The WHILE statement is used to loop through the code based on given condition. Here you will find the basic statement of WHILE statemento T-SQL. -- Declare a variable Declare @i int -- assign a value to variable SET @i = 0 -- condition to continue the loop WHILE @i BEGIN -- Statement inside the loop --INSERT INTO [Test].[dbo].[Emp] (Name) VALUES('ABC' + CONVERT(VARCHAR(3),@i)) -- Counter increment to end the loop SET @i += 1 -- Tio show the result of loop PRINT 'Loop ' + CONVERT(VARCHAR(3),@i) END Further reference: http://msdn.microsoft.com/en-us/library/ms178642.aspx