What will be the output of the following?

  • Atif-ullah Sheikh

    SSChampion

    Points: 12495

    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]

  • Karthik Palanivel

    Right there with Babe

    Points: 775

    I think the question is wrong.

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

  • john.david.birch

    Old Hand

    Points: 386

    ditto

    John

  • ralm

    Hall of Fame

    Points: 3117

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

    [font="Verdana"]Regards,
    Rals
    [/font].
  • alam.mushir-512938

    Mr or Mrs. 500

    Points: 517

    I think this is a typo.I want my point.:crying:

  • Rinkesh Kukreja

    Grasshopper

    Points: 19

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

  • UMG Developer

    SSChampion

    Points: 13482

    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... 🙂

  • UMG Developer

    SSChampion

    Points: 13482

    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.

  • Danny Ocean

    SSCertifiable

    Points: 6098

    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 !!!

  • Vera-428803

    SSCrazy

    Points: 2439

    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

  • paul.knibbs

    SSCoach

    Points: 15270

    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.

  • varghesetc

    Valued Member

    Points: 64

    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

  • psharma-1140604

    SSC Journeyman

    Points: 88

    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

  • Ben Schonenberg

    SSC Journeyman

    Points: 96

    is this a typo in the question?.

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

  • sharath.chalamgari

    SSCertifiable

    Points: 5680

    Hey the answer to the Question is Wrong.

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

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