What will the max id be?

  • palotaiarpad (12/19/2012)


    Could someone please explain, why is the identity resetted after a truncate?

    Because conceptually, TRUNCATE TABLE is closer to DROP / CREATE than to DELETE.


    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/

  • Easy one.. Remembering basics...

    --
    Dineshbabu
    Desire to learn new things..

  • SQL Kiwi (12/19/2012)


    Another good one. 19% wrong right now :blink:

    Yes, a good one. And in the last 6 hours the wrong rate has grown from 19% to 27%, which seems rather high for such an easy question.

    Tom

  • palotaiarpad (12/19/2012)


    why is the identity resetted after a truncate? For me is a possible source of inconsitency.

    As Lokesh has already explained, resetting the identity seed is a characteristic of the 'truncate' command. If you want to retain the seed then you use 'delete' instead. So, there's no inconsistency, it is just a case of using the right command according to your needs.

    At least you learnt something, so from that point of view it is a good question. 😉

  • palotaiarpad (12/19/2012)


    I'm also wrong, but i learned something. Could someone please explain, why is the identity resetted after a truncate? For me is a possible source of inconsitency.

    Hello, if resetting the identity is a possible source of inconsistency you may try using DELETE instead of TRUNCATE. DELETE will remove the data without resetting the identity.

  • Thanks for the easy one today.



    Everything is awesome!

  • Hmm, I answered too quickly (being on holiday now), thinking that without specifying the column list, the INSERT would expect values for both columns and hence would fail the inserts (even though an identity insertion wouldn't be allowed either). Doh. Thanks for what should have been an easy one!

  • Good Question, learned something today.

  • Weird, I was so sure I recently got a question wrong exactly because I thought truncate reseeded the identity and it actually didn't. Guess I was just confused. 😛

    Thanks for the good question, apparently I really needed to learn that one.

  • Thanks for the easy question.

    Saludos,

    "El" Jerry.

    "A watt of Ottawa" - Gerardo Galvan

    To better understand your help request, please follow these best practices.[/url]

  • It was easy, but really good for getting back to the basics. Thanks!

  • Good, straight-forward question on the basics. I'm surprised how many have gotten this wrong. I guess that means there are a lot of people learning a valuable point.

  • from beginning............

  • Thanks for memorized .

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

  • i think the answer will be "invalid object" as in last query we are dropping the table.

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

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