• Hugo Kornelis (2/11/2013)


    When picking my answer, I knew I had a 50/50 chance, because my mindreading skills are still not on par with my SQL skills.

    There were two options.

    1. The author knows very well what a batch is, and also knows very well that GO ends a batch. The phrasing of the question: "as 1 batch" was deliberate, as a sign that you should answer the question as if the GO lines are not there. He deliberately put them in to trap the people who just copy/paste the code.

    2. The author either doesn't know what a batch is, isn't aware what GO does, or wass not paying sufficient attention when adding that "as 1 batch" to the question. He meant that the entire code should be executed at once (allthough that is actually irrelevant, the results are the same if the batches, or evne the individual statements, are sent and executed one by one).

    In the first case, the entire batch will fail at parse and compile time, so none of the statements will actaully execute. You get an error message and nothing happens. The option "All statements will fail", though technically not 100% accurate (as there is a single failure of a whole batch, not multiple failures of incividual statements), comes close enough to be considered the correct answer.

    In the second case, the first batch will compile and execute successfully, the second batch will fail compilation and not execute, and the third batch will compile and execute successfully. The option "Only the 1st and 3rd statement will succeed but no rows will be returned", though technically not 100% accurate (as the 4th statement will also succeed), comes close enough to be considered te correct answer.

    I threw my dart to pick one of the two options, and failed. Oh well.

    I went through exactly the thought process Hugo describes, and answered that all three will fail (the only option that gives the same effect as a correct answer - the table is not created). I don't see how the given answer and explanation can be considered useful, as they are concerned only with running the code as three separate batches, and I thought it fair to assme that the person who wrote the question would know enough to understand the difference between running something as a single batch and running it as three batches (always assume the best of people unless there is evidence to the contrary is generally a good rule).

    I find it amazing that so many people think it a good question. The attempt by one of them to justify it even after the error has been pointed out

    demonfox (2/10/2013)


    Well, Let's not lost the question in the wordings; what's the point of three Go Statements , if the statement meant to remove them and then execute as it said

    which seems say "the author can't have got it wrong because I didn't spot the mistake" just plain silly. It's always just plain silly to say "whats the point is it meant what it said?", the sensible question is "what's the point of saying something doesn't mean what you say?".

    It isn't a good question, inn fact it is a terrible question, because it is not asking what the author apparently thought it asked. If it had meant what it said, it would have been a good question.

    Tom