How many Records Will Get Selected

  • Ninja's_RGR'us (6/11/2010)


    webrunner (6/11/2010)


    cathy.baker (6/11/2010)


    No matter if it's a bad question or a trick question. The answer is one. The question was "How many records are returned from the last SELECT?". That answer is 1 not 3. No matter if you execute the steps as one batch or individually the select statement returns one row.

    Actually, I ran the code and the last SELECT statement returns 3 rows. How did you get 1 row?

    I still think the question was more worthwhile than some other commenters are giving it credit for, but I also prefer when questions don't rely too much on a trick. I suppose the best advice is from those who caution against reading into the question author's intention and just step through the problem doing their best to simulate what will actually happen when the code runs.

    -webrunner

    How about this for this type of questions :

    Take a screenshot of the script then put the question category in syntax.

    Absoluetely no room for confusion here.

    That sounds good to me. I never run the code before answering the question, by the way. Not that I'm overly moralistic about people in general doing it; I just know that I won't really be testing my knowledge if I run the code to get the answer. And even if I get the question wrong, I can see what I really need to improve - in this case, syntax.

    Your suggestion probably won't satisfy people who think that real testing means including tricks or otherwise checking whether someone can get the answer even with misdirection and ambiguity thrown in. Certainly the real world works that way far too often, and such a skill can come in handy. But as far as I am concerned, that is testing some other skill - street smarts, for lack of a better term - and so even if it is useful, it almost calls for a different kind of scoring. Maybe. I don't know. It is difficult sometimes to articulate what's unappealing about relying on trick questions too much.

    - webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • Hugo Kornelis (6/11/2010)


    Another problem I have is that this kind of questions call for psychic powers on our part. Others have already commented that it might have been a honest mistake by the author, and we are suppose to answer based on a succesfull constraint creation (such errors and expectation have occurred in the past).

    I think that this was a terrible question precisely for this reason. I do not copy the QotD scripts, but try to figure out would happen if I were to run them. Because of it, I dismiss the simple syntax errors because it has happened in the past that the errors in the scripts were not intentional. The add constraint statement in the script has 2 highly visible errors in it, but this does not mean that they were intended. They could simply be a result of the author's oversight or lack of understanding about dangers associated with spelling object names in inconsistent with their actual names' case. Thus, I thought that the point of the question is to check our knowledge about the behavior of multiple insert statement (whether readers understand that each insert is a mini batch, meaning that if it terminates then next statements simply continue to run). I actually thought that it would be cool if the question asked what would be the mainkey value of the single record returned by the last select with -3 as correct answer (to test the readers' understanding of the identity behavior).

    As a matter of fact, even if I were to run this statement in SSMS and see that the last select returns 3 records, I would still answer 1 record.

    Oleg

  • Actually, I ran the code and the last SELECT statement returns 3 rows. How did you get 1 row?

    Actually, the goal should be to read and think.

    That being said, I am confused with how do we know when the question with an error in the script has a typo and when is it intentional?

    In reading the question, I see an error in the code. Seeing no error for an answer, I decide (incorrectly) that this must be a typo. So I mentally correct the code and continue on. With the correction to what appears to be a typo, I see that the answer has to be one of the answers shown. After selecting it, I am told that I am wrong. I then run the script to learn something new to find that there isn't anything new. Just confusion. If that is the goal, then the QoD was successful.

    Steve Jimmo
    Sr DBA
    “If we ever forget that we are One Nation Under God, then we will be a Nation gone under." - Ronald Reagan

  • Toreador (6/11/2010)


    Well I learnt something, though probably not what was intended.

    Believe it or not, I never realised that identity columns are ignored if you could insert into a table using that syntax, ie not giving a column list. I've always coded such things as

    insert into MyTable (mainvalue) values (-1)

    on the assumption that otherwise it would give an error about fewer values than columns!

    Me too! I thought it would fail there. I remember needing:

    insert into MyTable (mainvalue) values (-1).

    The best questions are those that require working knowledge of SQL like the bulk-logged mode question from Tuesday. Can't paste any code into an editor to get the answer; though I would never do that anyway :-D.

    But questions like this are fun and reinforce my knowledge of SQL.

    Ken

  • Mighty (6/11/2010)


    If the question was aiming at showing what the behaviour is of having "GO" in a batch, then it would have made sense to add the answer "The select statement will not be executed". Because if you would have thought that the syntax error would stop the batch, then the select would not have run at the end, so it would not even have returned 0 rows.

    Very true. Actually, if you had run the set of commands (i.e., the script) using SQLCMD with the -b (on error batch abort) switch vs. SSMS, the script would have failed on the ALTER TABLE command and the SELECT statement would never have executed.

    There was no explicit statement as to the method to run the QotD commands, so there should have been another answer "The SELECT statement will not be executed due to an error."


    [font="Arial Narrow"](PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.[/font]

  • A while ago there was one question with not intended mistake in the script and I lost points. Now I thought that this was just not intended mistake and lost points again. Shall we do premoderation? Because it's retarded.

  • sjimmo (6/11/2010)


    Actually, I ran the code and the last SELECT statement returns 3 rows. How did you get 1 row?

    Actually, the goal should be to read and think.

    That being said, I am confused with how do we know when the question with an error in the script has a typo and when is it intentional?

    In reading the question, I see an error in the code. Seeing no error for an answer, I decide (incorrectly) that this must be a typo. So I mentally correct the code and continue on. With the correction to what appears to be a typo, I see that the answer has to be one of the answers shown. After selecting it, I am told that I am wrong. I then run the script to learn something new to find that there isn't anything new. Just confusion. If that is the goal, then the QoD was successful.

    Right. Perhaps you responded before seeing my later reply.

    As I mentioned in my reply to another commenter, I never run the code before answering the question. Otherwise I would have a much better QOTD score! I agree with you that the goal should be to read and think. However, above I was specifically replying to another commenter who said that no matter what, the result was 1 row. So, I ran the code - after I had already answered the question and gotten it wrong, just to be clear. And I see 3 rows. So I was asking how the commenter got 1 row.

    I share your uncertainty about mentally correcting code, especially because there was no error as a choice (there couldn't be or else the trick would be revealed), but unfortunately in my case I missed concentrating on the syntax error even though for a moment I saw that there was something odd about the constraint definition. So reading carefully would not have helped me - it was a blind spot because I wasn't confident in my knowledge. So the "something new" for me was that I need to know my syntax better.

    But as Hugo stated, the documented instances of unintentional typos may have thrown off people who did spot the syntax error, leading them to mentally correct the error when they shouldn't have. I think the only way to avoid that problem is to avoid any mental corrections and just take the code at face value.

    For those who were confident that the constraint definition syntax was wrong, then I don't see mentally correcting it as the right way to proceed. Just assume the error happens and extrapolate what happens next. That would get you the right answer, regardless of the author's intentions. The only feasible proposed solution I have seen was by another commenter who suggests setting the question category to Syntax and using a screenshot of the code to discourage copy and run responses. But in its own way, that solution involves relinquishing the trick question aspect - which is fine by me, but I think not fine with those who like trick questions.

    - webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • The problem with questions based on syntax errors is that the person answering the question does not know if the syntax error is the issue or if the question is testing knowledge of how SQL works.

    In this case I did not know what was going on so I guessed. I did not see the syntax error because I did not know what the code was for. The question explanation told me there was a syntax error, but all I learned was that the code I did not understand was typed wrong.

    The moral of my story: At least the question pushed me to look up info on constraints.

  • Chad Crawford (6/11/2010)


    I also second guessed the intent of the question. Oh well, that's they way it goes sometimes. Still glad to have a QOD to look forward to each day.

    Thanks,

    Chad

    This is also my view. Oh well time to move on hopefully Monday's question won't be a trick... or maybe it won't be a trick but a real unintend syntax error. Either way I look forward to the question and the discussion.

    ---------------------------------------------------------------------
    Use Full Links:
    KB Article from Microsoft on how to ask a question on a Forum

  • My initial reaction was that it would return one row, but I thought this is too easy for a question worth 3 points. So I looked a little more and saw the syntax error on the constraint, so I got it correct. But only because of the point value of the question.

  • The learning experience would have been helped greatly by having more than 'due to the syntax error' in the explanation. For me my first response was 'What syntax error?' which is why I got it wrong, but I was no closer to understanding why. Which item?

    I'm just saying, it would have been helpful.

    The GO lesson is my take away.

  • UMG Developer (6/11/2010)


    My initial reaction was that it would return one row, but I thought this is too easy for a question worth 3 points. So I looked a little more and saw the syntax error on the constraint, so I got it correct. But only because of the point value of the question.

    I likely would have looked at it harder had I noticed it was 3 points. I did think it seemed oddly simple, but what is easy for one person is hard for another, so I didn't give it much thought past that. I know there are plenty of questions that are hard for me that others have no problem with. I don't usually look at the points until I'm done.

    --------------------------------------
    When you encounter a problem, if the solution isn't readily evident go back to the start and check your assumptions.
    --------------------------------------
    It’s unpleasantly like being drunk.
    What’s so unpleasant about being drunk?
    You ask a glass of water. -- Douglas Adams

  • I agree: I assume that the creation of the check constraint was to be corrected before attempting to insert the records.

  • An easy 3 points.

    Tom Garth
    Vertical Solutions[/url]

    "There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." -- Will Rogers
  • I second Ninja's_RGR'us recommendation regarding the script screenshot.

    For two reasons:

    #1) it requires at least a little more effort to run it before answering (for those who otherwise would just do a copy and paste) and

    #2) There would be no room for guessing if a typo is a typo or intended.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

Viewing 15 posts - 31 through 45 (of 75 total)

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