Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Inserting million of rows with help of while loop

$
0
0

In a table with 10 rows of data and five columns i need to insert a millions of rows repeating first 10 rows using while loop in sql server 

My code is:

DECLARE @x int,
              @y int,
             @Name varchar (100),
             @Address varchar (100) 
  Select   @x = 1,
              @y = 100,
             @Name = 'Sri',
             @Address = 'Hyderabad'
WHILE @x <= @y
BEGIN
insert into dbo.T_NoIndex
Select @Name + CAST(@x as varchar (100)), 
          @Address + CAST(@x as varchar (100)),0,1000
     
 Set @x = @x +1     

END

But I am able to insert only the first row multiple times, but i want to insert all rows of table simultaneously again with a variable


Viewing all articles
Browse latest Browse all 23857

Trending Articles