SQL Server with Mr. Denny - Quick and dirty way to run a batch over and over
"Everyone has their favorite way or running a block of code over and over again. If you have to run an entire batch over and over again there is nothing as quick and easy as using the “GO n” syntax. When you put a number after the GO batch separator SQL Server Management Studio (as well as SQLCMD) will run that entire batch however many times that you have specified.
Recently I needed to create some dummy data in a table, so instead of writing a loop that counted the number of times the loop ran, I simply used code like this.
...
This just made me shake my head and sigh at just how much I don't know. I've been using SQL Server since 4.21a, writing and dreaming in T-SQL, and I never knew the GO statement had a [Count] parameter (as in repeat the given statement [Count] times... sigh.
No comments:
Post a Comment
NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...
ALL comments are moderated. I will review every comment before it will appear on the blog.
Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...
I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...
Please see my comment policy for more information if you are interested.
Thanks,
Greg
PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...