30 September,2019 by Tom Collins
Question: I'd like to execute a batch sql statement through SQL Server management studio multiple times and avoid using a loop statement or other similar constructs . I'm doing some testing requiring multiple returns of recordsets and would like a simple approach - for ad hoc queries
Answer: Looking at the SQL Server documentation for the sql server utility GO - indicates the syntax is GO [count].
This means the queries triggered as part of the batch executed will execute the amount of times listed after GO. By default it's 1 , but if you specify a positive integer - the statement will execute that amount of times
Note: you can't use this feature as part of a stored procedure, typically you use it through SSMS or sqlcmd.
An example of the GO [count]) is the following - which executes the the select * from sys.databases 100 times
select * from sys.databases GO 100
Read more on SQL Server and batch processes
How to delete millions of rows in batches
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |