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

  • Home
  • SEARCH
  • 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 3612886
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:03:22+00:00 2026-05-18T22:03:22+00:00

Was a bit suprised today to discover that my auto-increment primary key still gets

  • 0

Was a bit suprised today to discover that my auto-increment primary key still gets incremented when an insert statement errors, with the result that we have “missing” numbers in our table.

Is there any reason why SQL was designed this way? And is there any way to override this behaviour?

I am accessing through Linq-to-SQL.

  • 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-18T22:03:23+00:00Added an answer on May 18, 2026 at 10:03 pm

    this is by design to deal with concurrency and make it as fast as possible (what would happen if 3 inserts happens at the same time and 1 is rolled back..that would mess up everything)..when an inserts starts sql server determines the value of the identity..if a rollback happens those values are not reused..there is nothing you can really do unless you want to run DBCC CHECKIDENT after every rollback

    If you need a query that will identify gaps, take a look at this How to return all the skipped identity values from a table in SQL Server

    The next version of SQL Server will have sequences which might help you with some of this stuff, take a look here: A first look at sequences in SQL Server Denali

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

Sidebar

Related Questions

I'm a bit surprised by System.Collections.Generic.SortedList, in that It requires me to use <key,
Today I have been playing a bit with the LinearLayout and have been suprised
Today, i was a little bit surprised about the behavior of c structure vs
Bit of a puzzle for you.... I have a 730px wide, auto height div.
I have googled for it but I am a bit surprised that I couldn't
I found out that the following code gets accepted by Visual C++ 2008 and
I'm perplexed. At CodeRage today, Marco Cantu said that CharInSet was slow and I
Once again, I'm questioning a longstanding belief. Until today, I believed that the alignment
I'm a bit surprised that it's so complicated to get a charset of a
I'm a bit surprised that it's so complicated to get a charset of a

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.