INSERT INTO

  • Glad I checked the discussion here! Feeling much better about getting it wrong when I was really right. Thanks for the question anyways.

  • I don't see what we were supposed to get from this question, and I got it wrong...oh well! There is always tomorrow's QotD ๐Ÿ˜€

  • Seems like the biggest responses are generated from QOTD answers that are wrong.

    A plot to increase activity on the site perhaps?? :hehe:

    Converting oxygen into carbon dioxide, since 1955.
  • Steve Jones - SSC Editor (9/14/2011)


    This problem with the question is entirely my fault, not Ron's. I copied over the code, making a mistake after testing it when I was correcting formatting. The second set of inserts should have inserted PKs of 1, 2, 2, so that the result was two.

    I have corrected the code, and also awarded back points to this point in time.

    My apologies.

    Not sure how I got the old version of the Question with the second set of PKs being 1, 1, 1, after Steve made the changes but I also had to guess between 0 or 2 for the correct answer for the second select. And ofcourse I chose incorrectly.

    However, I think this was a very good question for pointing out the differences in the results of the insert statements.

  • Not sure how I got the old version of the Question with the second set of PKs being 1, 1, 1, after Steve made the changes but I also had to guess between 0 or 2 for the correct answer for the second select. And ofcourse I chose incorrectly.

    However, I think this was a very good question for pointing out the differences in the results of the insert statements.

    Got the wrong version, too. Did not choose either "returns 0" or "returns 2" checkbox, since neither was the right answer, and there goes my point.

    I guess I will always have the satisfaction of a job well done.:cool:

  • jlennartz (9/14/2011)


    Steve Jones - SSC Editor (9/14/2011)


    This problem with the question is entirely my fault, not Ron's. I copied over the code, making a mistake after testing it when I was correcting formatting. The second set of inserts should have inserted PKs of 1, 2, 2, so that the result was two.

    I have corrected the code, and also awarded back points to this point in time.

    My apologies.

    Not sure how I got the old version of the Question with the second set of PKs being 1, 1, 1, after Steve made the changes but I also had to guess between 0 or 2 for the correct answer for the second select. And ofcourse I chose incorrectly.

    However, I think this was a very good question for pointing out the differences in the results of the insert statements.

    Every1 got the same options ( old version) ....not alone u dude

    Regards,

    Sushant

    Regards
    Sushant Kumar
    MCTS,MCP

  • BarbW (9/14/2011)


    I don't see what we were supposed to get from this question, and I got it wrong...oh well! There is always tomorrow's QotD ๐Ÿ˜€

    As listed in the support of the correct answers it was to draw attention to New T-SQL Programmability Features in SQL Server 2008

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • A good question marred for some by a typo.

    But it was a typo that added to the fun - it was perfectly sensible to try to reason about what the typo was likely to have been and which incorrect option should be ticked to make the 3 up to 4. And when it turned out that the two obviously likely typos both led to ticking the same incorrect option that was a bonus.

    Since a correct answer wasn't possible (I though "insert into cuss2 returns an error" and "insert into cuss2 doesn't return an error" couldn't both be ticked, that would be a violation of English) it boiled down into deducing what the typo was. It could either be an error in the code, maybe the first values in the three inserts for cuss2 should have been 1,2,2 (as in the insert of three rows for cuss1) in which case the second select would return 2, so ticking that option would win, or an error in the reply options - maybe that 2 for the second select should have been 1 (the idea being that we might be tempted to say first one is 0, oh so is the second one, which couldn't have happened if it had been the 0 that should have been 1) so again ticking the same option would win. So of course I ticked that one and got the point, since whichever simple typing error had happened that was the one to tick.

    Tom

  • Tom.Thomson (9/14/2011)


    Since a correct answer wasn't possible (I though "insert into cuss2 returns an error" and "insert into cuss2 doesn't return an error" couldn't both be ticked, that would be a violation of English) it boiled down into deducing what the typo was.

    I argue that your conclusion that choosing both "insert into dbo.cuss2 returns an error" and "insert into cuss2 doesn't return an error" requires the unjustifiable assumption that those answers implicity include the qualifier that they apply to ALL inserts into dbo.cuss2 (i.e., either all inserts return an error or all inserts do not return an error). I say that the assumption is unjustifiable because the point of the question seems to be the demonstration of the different behaviors of the INSERT INTO table_name VALUES syntax versus repeated INSERT INTO table_name SELECT value1, value2 statements (I believe the question writer described it as such). The behavior specifically demonstrated by the presented code is that the entire INSERT INTO table_name VALUES statement fails and is rolled back if any of the PK values in the VALUES set violates the PK constraint, while each individual INSERT INTO table_name SELECT value1, value2 statement succeeds or fails (and is committed or rolled back) irrespective of the fate of the others. It wouldn't make much sense, then, to read the "ALL inserts" qualifier into the two answers, because even the corrected code is written such that at least one INSERT INTO dbo.Cuss2 succeeds and at least one INSERT INTO dbo.Cuss2 fails and returns an error message to demonstrate the different behaviors of the "Cuss1" INSERT and the "Cuss2" INSERTs.

    Under these conditions, I would say that even in the corrected question, there are 5 answers that are correct because they reflect a result that occurs when running the presented code. Since the question asks the answerer to identify 4 of them, I would argue that any combination of 4 of those 5 would be correct, yielding a total of 5 different ways the question could be answered correctly.

    Jason Wolfkill

  • wolfkillj (9/14/2011)


    Tom.Thomson (9/14/2011)


    Since a correct answer wasn't possible (I though "insert into cuss2 returns an error" and "insert into cuss2 doesn't return an error" couldn't both be ticked, that would be a violation of English) it boiled down into deducing what the typo was.

    I argue that your conclusion that choosing both "insert into dbo.cuss2 returns an error" and "insert into cuss2 doesn't return an error" requires the unjustifiable assumption that those answers implicity include the qualifier that they apply to ALL inserts into dbo.cuss2

    It does indeed require an assumption about what the answers mean. So the question is whether to treat "insert..." as meaning "An insert...." (in which case your interpretation is correct) or as meaning "The whole insertion process" which precludes your interpretation. I wanted to choose an interpretation that gave me 4 answers if there was a simple typo, because I didn't believe the question would have been quite so deliberately irritating as to allow your interpretation, so I chose the one that did that. However, choosing the other is equally valid.

    Under these conditions, I would say that even in the corrected question, there are 5 answers that are correct because they reflect a result that occurs when running the presented code. Since the question asks the answerer to identify 4 of them I would argue that any combination of 4 of those 5 would be correct, yielding a total of 5 different ways the question could be answered correctly.

    Yes, but the automatic scoring system isn't capable of coping with that situation (at least I believe it isn't; the question submitting mechanism doesn't permit one to specify such a correctness condition), so in that case there could have been no misprint making one of the last two count values correct, leaving us again with only one correct combination of options (the one that includes both the statements about whether "insert into cuss2" returns an error or not and neither of the two statements about the last select).

    Anyway, I imagine we'll end up with the question being corrected and points awarded to those who didn't get them. That's what usually happens with something like this.

    Tom

  • Thanks for the question.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Thanks for the question. I've only submitted a couple over the years and know how quick others are to jump on your mistakes / typos (easily done though).

    Sweated over this one for a few minutes though before working it out.

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. โ€• Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

  • Nice question ... pls amend the second SELECT statement to have a return value of 1 and not 2.

    Kwex.

  • the code in the second section should be like this:

    CREATE TABLE #Cuss2

    (cid int NOT NULL, cut varchar(25) NOT NULL,

    ph varchar(20) NOT NULL, adx varchar(50) NOT NULL,

    CONSTRAINT PK_Cuss2 PRIMARY KEY(CID));

    GO

    SET NOCOUNT OFF

    INSERT INTO #Cuss2( cid, cut, ph, adx)

    VALUES (1, 'cust 1', '(111) 111-1111', 'address 1');

    INSERT INTO #Cuss2( cid, cut, ph, adx)

    VALUES (2, 'cust 2', '(222) 222-2222', 'address 2');

    INSERT INTO #Cuss2( cid, cut, ph, adx)

    VALUES (1, 'cust 2', '(222) 222-2222', 'address 2');

    GO

    ๐Ÿ™‚

  • My answer was correct, think this is another typo,but i would think T-SQL are quite easy to verify.

    โ€œWhen I hear somebody sigh, โ€˜Life is hard,โ€™ I am always tempted to ask, โ€˜Compared to what?โ€™โ€ - Sydney Harris

Viewing 15 posts - 61 through 75 (of 122 total)

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