What will be the output of the following?

  • I had got the output as -1,0,1. Then how is it possible that my answer is wrong......:w00t:

  • Extremely Sorry to all but the result was mistakenly suggested as the correct one. I have sent an email to the webmaster to either change the answer or to remove this question.

    Apologies to all:crying:[font="Arial"][/font]

  • Hi all

    if you wont to get the out put as -1,-2,-3

    then the Question should be corrected as

    create table MyTable (

    mainKey int not null identity (-1,-1)

    )

    go

    insert into myTable default values

    insert into myTable default values

    insert into myTable default values

    Select * from MyTable

    According to the Question the answer is

    -1,0,1

    Thnks .............

  • I am completely agree with Broadcaster

    either the Question is wrong or the answer is incorrect.

    >>first - all available answers are wrong. "-1,-0,1" is the better looking although you will not get "-0"

    >>second - with identity (-1,1) you can only get -1, 0, 1. If you want to get -1,-2,-3 you would need >>identity(-1,-1)

    >>There is something wrong with either question or with the answers.

  • I agree with prabhakantha, the anwer should be -1, 0, 1 since your seed is positive 1 and not negative 1.

  • Anyone here think QoD questions and answers should be checked independently before they are released?

  • The answer is definitely wrong..:w00t:

  • david.wright-948385 (6/28/2010)


    Anyone here think QoD questions and answers should be checked independently before they are released?

    @david-2 - that has been suggested before. On numerous occasions. And several people have volunteered to assist in checking. The answer by Steve thus far has always been tthat this has been tried, and failed because the volunteer answer checkers often did not get around to providing feedback in time, becuase they have lifes of their own that sometimes get in the way of giving time to community.

    Personally, I am very disappointed with this particular question. I have submitted several questions of my own, and while some of them had errors as well, errors in the code were not among them. If you invest the effort to write up a question, think up some believable distractors, and submit it to SSC, why not take the 5-10 seconds additional effort to copy the code in SSMS and hit Execute to check for typos? (Or, even better, write the code in SSMS first, then use copy/paste when writing the question).

    @sqlbuzz - I do realize that my words are harsh. Please do not let that deter you from submitting more questions in the future. But do make sure to copy the code in SSMS (or QA, or sqlcmd.exe. or whatever) and execute it to make sure you have no unintended errors in the code.

    @steve-2 - have you considered adding a checkbox "I have copied all code ocntained in the question to Management Studio, executed it, and verified that it contains no errors, except those intended to be in the question"? Not for real legal purposes, of course, but as a gentle reminder to the author to use SSMS to double check for typos. I think that might at least reduce the chance of these errors happening.

    I think it has been sufficiently said that with the code as is, there is no correct answer but the "-1,-0,1" option is closest to the orrect "-1,0,1". If the author had published the intended code, I would still have had to disagree with the question, since then there would have been two correct options: "-1, -2, -3" and "-3, -2, -1" both are the same set (remember that a set is an unordered collection!), and since there is no ORDER BY in the query, these two could both have been returned (as well as the other 4 possible permutations).


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • ya .. give us the point ..

    as question and answer both are incorrect.

    from the question it is very clear that sql will increement with +ve 1.

    to get -1,-2,-3 you have to provide increement value -ve 1

    Question is Misleading.

  • first - all available answers are wrong. "-1,-0,1" is the better looking although you will not get "-0"

    second - with identity (-1,1) you can only get -1, 0, 1. If you want to get -1,-2,-3 you would need identity(-1,-1)

    There is something wrong with either question or with the answers.

  • BOL:

    IDENTITY [ (seed , increment) ]

    seed

    Is the value that is used for the very first row loaded into the table.

    increment

    Is the incremental value that is added to the identity value of the previous row that was loaded.

    The answer should be: "-1, 0, 1" :hehe:

    -------------------------------
    www: 3CityDBA.pl

  • Someone made a typo - correct answer for that sample is -1, 0, 1 - no doubt.

    So give us points and take out points to author of this QoD 😉

  • I totally agree with you 🙂

  • Yes, even I have executed this query in SSMS 2008, and I got -1,0,1. I think there is some typo/error in the question itself

  • correct answer is -1,0,1

    for -1,-2,-3 identity(-1,-1) is required

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

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