June 28, 2005 at 3:16 pm
My book under batches seems to contradict itself.
It says: "If a syntax error occurs anywhere in the batch, the entire batch is canceled."
Then below this set of bullets it says: "When a batch is submitted for processing, it's parced, resolved, optimized, compiled, and then executed. During execution, if any single statement fails, the batch continues with the next statement until it finishes processing."
It then gives an example with the create statement. "If you batch has five Create Table statements in it and statement 3 causes an error, SQL server creates tables 1, 2, 4, and 5. Table 3, however, isn't created."
Sounds like a contradiction to me! Which is correct?
Page 396 of book Teach Yourself SQL Server 2000 in 21 days.
June 28, 2005 at 3:19 pm
if that "batch" has GO in it, then GO is a batch separator therefore each create table is one batch
* Noel
June 28, 2005 at 3:47 pm
Thanks that is a good point. I hadn't realized that.
HOWEVER, the statement itself is contradictory. "When a batch is submitted for processing, it's parced, resolved, optimized, compiled, and then executed. During execution, if any single statement fails, the batch continues with the next statement until it finishes processing."
In either case, there is NO MENTION OF GO. In the case you described the emphasis is not on the batch but on the importance of using the keyword GO which does not appear in either statement.
In fact there are no examples in the book that show a GO after each statement--not under Batches anyway.
So i guess to qualify my question, without the GO statements, the entire batch will be canceled? With the GO statements only that one part will be canceled.
To be clear then, a batch is anytime you write code including executing a store procedure in isqlw? A script only differs in that after GO is typed more code is typed and another go. Thus as it says: "A script is a set of one or more batches that are saved as a group." IS the emphasis here on SAVED? So then is it NOT a script if it is not SAVED?
Sorry, this might seem self explanatory, but the book was not clearer on what a batch was. I only got an idea after reading Noel's comment and looking back at the book. I think it is much clear but i would like some confirmation. Thanks!
June 28, 2005 at 4:44 pm
Looks to me like the server is differentiating between a syntax error and a error during execution. They are different things. For instance you've got 'craete table' somewhere in your script it'll bomb out with an error during parsing, but if you try to create a table with the same name of one that exists already in the database, only that statement will fail during execution of the batch.
HTH
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply