Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6762273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:18:02+00:00 2026-05-26T14:18:02+00:00

Hi guys I just have one quick question: what happens when an insert statement

  • 0

Hi guys I just have one quick question:

what happens when an insert statement fails on an identity column?

Is it possible that say for example that if I insert a row with an identity column, that identity column will be 1, and insert again but that fails and does not insert and data. Then try to insert again and that identity for that row is now 3?

Any advice will be much appreciated.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:18:02+00:00Added an answer on May 26, 2026 at 2:18 pm

    It depends on what the cause of the fail on data insert is. If for example the values are invalid (wrong types), then the identity value won’t be incremented. However, if the first insert is successful, but is then removed (by a transaction failed and rolled back), then the identity value IS incremented.

    -- Next identity value = 1
    INSERT INTO Table1 (
        field1)
    VALUES ('a')
    
    -- Next identity value = 2    
    BEGIN TRAN
    INSERT INTO Table1 (
      field1)
    VALUES ('b')
    
    -- Next identity value = 3    
    ROLLBACK TRAN
    
    -- Next identity value = 3, although the insertion was removed.    
    INSERT INTO Table1 (
      field1)
    VALUES ('c')
    
    -- Next identity value = 4
    

    The first insert will have identity column value = 1, the second one fails, and the third one will have identity column value = 3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, just wondering if this one is possible I have an app that
Hey guys, quick question, I have an id that is applied multiple times on
Just a quick question, that I cannot fathom out, hope you guys and girls
Hey guys just a quick question, I am posting mp3s in dialog boxes each
I have one field that I need to sum lets say named items However
Just need to confirm one thing that i have searched enough on How can
I have just one method that I need several different classes to access and
Ok guys, this question is related to my previous one. If I have set
Ok guys just a small game: I have some specifications for a project. At
Guys I know this question is silly but just to make sure: Having in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.