What will be the output of the following?

  • malleswarareddy_m (6/27/2010)


    sheik (6/27/2010)


    The table should be created with the identity (-1,-1). Then only we can get this result. Must be a typo error???.

    It's correct.

    Right.

    Create Table MyTable1( mainkey int not null identity (-1,-1))

    GO

    insert into MyTable1 default values

    insert into MyTable1 default values

    insert into MyTable1 default values

    Select * from MyTable1

    drop table MyTable1

    Now this code gives -1,-2,-3

    Typing error. Lost my point...

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

  • I think the question is wrong.

    incase identity(-1,-1) then the answer ll be correct other wise will get -1,0,1 only.

  • ditto

    John

  • Must be typing mistake from the author of this question... but how can we have "-0" in the result. 😉

    [font="Verdana"]Regards,
    Rals
    [/font].
  • I think this is a typo.I want my point.:crying:

  • I am getting -1,0,1 as the final output. Could somebody recheck the answer.

  • Interesting that the - got in the wrong place in the question, I saw the "-0" and thought that something might be up, but I picked that option anyhow since no other one was possible. I didn't think about that that - might have belonged up in the question.

    At this point I agree that the correct answer needs to be changed, and points retro-actively awarded... 🙂

  • Also, if the identity increment was -1, then both option 1 and 3 would be correct, as there is no clustered index to order it, and no ORDER BY statement specified, so either -1, -2, -3 or -3, -2, -1 could be the result.

  • Hi,

    I think, before publish any question, it should be check by experts.

    bcz, we all here to increase are knowledge and its spread wrong message to all. So i request to publisher, please check the question before publish.

    Thanks
    Vinay Kumar
    -----------------------------------------------------------------
    Keep Learning - Keep Growing !!!

  • If you start with -1 and add 1, the correct answer according to me is -1, 0, 1.

    I agree with a previous post that to get -1, -2 -3 you would have to start with -1 and substract 1.

    Identity would then be identity (-1,-1).

    Not often that I disagree with the correct answer, but this time I do because I think the answer is wrong.

    Vera

  • I also expected the answer to be -1, 0, 1--glad to hear I'm not alone in this! And the explanation given seemed largely irrelevant--I never thought a primary key couldn't be negative.

  • bazzkar (6/26/2010)


    Comments posted to this topic are about the item <A HREF="/questions/IDENTITY/69598/">What will be the output of the following?</A>

    I am getting -1,0,1 only..

    Kindly explain

  • Hi,

    Identity has been set (-1, 1) that means first row will start with -1 and there will be 1 increment in subsequesnt rows so the answer should be

    -1, 0, 1

  • is this a typo in the question?.

    I think to get this answer the declartion of the identity should by (-1,-1)

  • Hey the answer to the Question is Wrong.

Viewing 15 posts - 16 through 30 (of 144 total)

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