Bloggin in the UK RSS 2.0
 Saturday, February 11, 2006

I was compiling a release script the other day, and needed to check if all data items in a column were unique before adding a Unique constraint to a table. I wanted a way to stop Query Analyzer (QA) from executing the batch if the check revealed there were duplicate items in the column. I tried a few obvious things like Return and raiserror but these didn't work. I then realised that the issue lay with the GO command. I found this in BOL "GO is not a Transact-SQL statement; it is a command recognized by the osql and isql utilities and SQL Query Analyzer." unfortunately there isn't a corresponding STOP command so you cannot easily perform a test in T-SQL and then tell Query Analyzer (QA) to stop processing the rest of the batch.

I did however find a dirty way around this problem. Using a While loop and the Print command I was able to repeatedly display a message to the user explaining the problem and instructing them to cancel the execution. Not very elegant but it did work.

BOL Search Terms: Batches, Batch Processing

Saturday, February 11, 2006 1:34:33 PM (GMT Standard Time, UTC+00:00)  #    Comments [3] -
SQL Server
Archive
<August 2008>
SunMonTueWedThuFriSat
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008
Charlie Barker
Sign In
Statistics
Total Posts: 139
This Year: 20
This Month: 1
This Week: 0
Comments: 52
Themes
Pick a theme:
All Content © 2008, Charlie Barker
DasBlog theme 'Business' created by Christoph De Baene (delarou)