Results 1 to 5 of 5

Thread: [RESOLVED] identity seed incremented in transaction

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Resolved [RESOLVED] identity seed incremented in transaction

    HI,

    I have the attached

    On inspecting my T_SQL I think I need to insert Rollback in the INSERT part of the SPROC. For example when USERID (field) was missing in tb_Translog, the identity for that table was still executed because the next correction entry had skipped a record.

    I wonder if someone can give some advice pls.

    PS I have included a ROLLBACK for every error message but I am still getting the indentity seed incremented. I am updating the file. Anyone can give me some expert help on these transactios pls
    Last edited by angelica; Sep 16th, 2008 at 04:25 PM.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: identity seed incremented in transaction

    A Rollback does not affect Identity values. Once an Identity value has been used it is gone for good.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: identity seed incremented in transaction

    Dont quite understand it.

    If I have an error or condition is not satisified I put a ROLLBACK. The contents of the record do NOT got through but the identity seed is incremented ! Is this normal even though I put it inside a transaction?!
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: identity seed incremented in transaction

    The Identity value is not affected by the Rollback command. The value can only be generated one time and one time only. By the time the Rollback is sent the action has already completed. You can do other things such as getting the current identity of the table in question at the start of each insert and then if a rollback occures re-seed the table to that value.

    PS by the way I think this is way to much trouble to even consider.
    Last edited by GaryMazzone; Sep 16th, 2008 at 03:11 PM.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: identity seed incremented in transaction

    ok Gary,

    Thanks to you both, at least I set my mind at rest Im doing it the right way.

    I wont go into that trouble as you said. cheers
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width