QOD 09/29/2003

  • What about explanation of today's QOD?

    I'm not satisfied with it. Replace ROLLBACK by COMMIT and what? The result wil be the same.

    The @@ROWCOUNT returns the number of rows affected by the last statement (before the one, using @@ROWCOUNT). Neither ROLLBACK nor COMMIT doesn't affect any rows directly (in spite of INSERT, UPDATE, etc.).

    So the result equals zero in any case.

  • This has to be the most ridiculous QOD I've seen. The result you get depends on which database you run the query against and seeing as the database that the query is being run against is not stated in the question then answer 1 (an error) is a perfectly correct answer. I WANT MY POINTS!!!

  • Well, in the absence of any other information, I assumed that the question was about row counts, and that the SQL UPDATE statement itself would not produce an error.

    The red-herring with "SET NOCOUNT ON" was curiously not mentioned in the answer - this command switches off the "x rows affected" messages, but does not affect the rowcount returned by @@ROWCOUNT.

    Anyway, as OZernov said, the answer itself also misses the other red-herring set by the author him/herself which is that the presence of other SQL statements between the UPDATE and the PRINT @@ROWCOUNT statements will reset the @@ROWCOUNT variable.

    I like the question though! A quite neat and simple T-SQL problem.

    --

    Si Chan

    Database Administrator

  • quote:


    This has to be the most ridiculous QOD I've seen. The result you get depends on which database you run the query against and seeing as the database that the query is being run against is not stated in the question then answer 1 (an error) is a perfectly correct answer. I WANT MY POINTS!!!


    Why would the results vary. If you run it in the Northwind db of course it would fail due to the table not existing. The table name though is just a representation of the overall problem. If you run the same type query against any database, you should get the result of 0.

    Brian Knight

    bknight@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/bknight

  • Doesn't there have to be an "END TRANS" for this statement? I'm not familiar with using transactions, but I could have swore you had to have an END in there.

  • quote:


    Doesn't there have to be an "END TRANS" for this statement? I'm not familiar with using transactions, but I could have swore you had to have an END in there.


    To end the TRAN, you can either do a COMMIT or a ROLLBACK with altering results. Checkout BEGIN TRANSACTION in BOL for more info.

    Brian Knight

    bknight@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/bknight

  • Wouldn't the 'rollback' rollback the update statement before it is committed, which is why the @@rowcount is 0?

  • quote:

    --------------------------------------------------------------------------------

    This has to be the most ridiculous QOD I've seen. The result you get depends on which database you run the query against and seeing as the database that the query is being run against is not stated in the question then answer 1 (an error) is a perfectly correct answer. I WANT MY POINTS!!!

    --------------------------------------------------------------------------------

    You cannot have points for raising confusing existential q's like what if the field does not exist, what if the table does no exist, what if the SQL server does not exist, and so on. Appeal denied.

  • I thought the only ridiculous part of the question is that it was damn easy.

    The QOD would be a problem if it weren't for the rollback, because the au_id values are not defined in the question as unique.

    Data: Easy to spill, hard to clean up!

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply