Repeat a SQL command multiple times


How to repeat a SQL command multiple times

To run a SQL command multiple times use the Go command and pass the number of times you want to execute the command as a parameter:

1
2
INSERT INTO [MyTable] (fruit, quantity) VALUES ("Banana", 12);
GO 5

The above command repeats the INSERT command 5 times. This behaviour can be useful if you want to populate a database table with some test data. This command came in handy recently when I needed to fill a database table with 150 rows so I could see how a webpage I was writing looked when there were lots of data.

References

comments powered by Disqus