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 6991113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:27:03+00:00 2026-05-27T19:27:03+00:00

Ok, I am a bit less experienced in database topics, but consider the situation

  • 0

Ok, I am a bit less experienced in database topics, but consider the situation where you have a field named id in your table, and it’s Indexable/Increment-seeding.

So maybe you have rows 1-60 , so id is between 1-60, and the increment is at “61”.

Well if you delete rows 30-50, shouldn’t the increment go back down to “31”? Filling in those 30-50 ids, and then going back to 61?

My Question::: Why doesn’t MSSQL / SQL Server, do this? The missing unused ids between 30-50, are never to be used again.

Further, what if you manually inserted some rows, between id 500-600? When the increment gets to “500”, will it not give a “duplicate key” error? ???

So if you have some sort of table that is constantly changed by every user—deleting, inserting, deleting, inserting, you better hope id is bigint, because it’s going to quickly go into the 1,000,000+ area if you have enough users.

  • 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-27T19:27:04+00:00Added an answer on May 27, 2026 at 7:27 pm

    If you are using autoincrement fields, it is highly recommended to just let SQL Server handle the values for you. It does so in such a way as to minimize integrity conflicts.

    That said, if you really want to reset the id values after a large delete, consider using TRUNCATE TABLE (which will reset the autoincrement value automatically) if you are purging the entire table, or DBCC CHECKIDENT if you need finer control over how this works.

    EDIT:

    This is to demonstrate the behavior of SQL Server when there is a manually-perpetrated gap in autoincrement ID values:

    BEGIN TRAN
    
    create table #t1 (id int identity, data int)
    
    insert into #t1 (data) values (1)
    insert into #t1 (data) values (2)
    insert into #t1 (data) values (3)
    insert into #t1 (data) values (4)
    
    select * from #t1
    
    dbcc checkident(#t1, reseed, 10)
    
    insert into #t1 (data) values (5)
    insert into #t1 (data) values (6)
    insert into #t1 (data) values (7)
    insert into #t1 (data) values (8)
    
    select * from #t1
    
    dbcc checkident(#t1, reseed, 5)
    
    insert into #t1 (data) values (9)
    insert into #t1 (data) values (10)
    insert into #t1 (data) values (11)
    insert into #t1 (data) values (12)
    insert into #t1 (data) values (13)
    insert into #t1 (data) values (14)
    insert into #t1 (data) values (15)
    insert into #t1 (data) values (16)
    
    select * from #t1 -- this will demonstrate that SQL Server is quite happy to duplicate IDs if you have manually introduced a gap and then reset the ID to a lower value...
    
    truncate table #t1
    
    insert into #t1 (data) values (1)
    insert into #t1 (data) values (2)
    insert into #t1 (data) values (3)
    insert into #t1 (data) values (4)
    
    select * from #t1 -- this will show that TRUNCATE TABLE does (yes, really!) reset the autoincrement id value.
    
    create table #t2 (id int identity primary key, data int)
    
    insert into #t2 (data) values (1)
    insert into #t2 (data) values (2)
    insert into #t2 (data) values (3)
    insert into #t2 (data) values (4)
    
    select * from #t2
    
    dbcc checkident(#t2, reseed, 10)
    
    insert into #t2 (data) values (5)
    insert into #t2 (data) values (6)
    insert into #t2 (data) values (7)
    insert into #t2 (data) values (8)
    
    select * from #t2
    
    dbcc checkident(#t2, reseed, 5)
    
    -- the errors you are about to get should demonstrate that if there is an integrity constraint (in this case, the ever-popular PRIMARY KEY constraint) you will get errors when attempting to insert duplicates.
    
    insert into #t2 (data) values (9)
    insert into #t2 (data) values (10)
    insert into #t2 (data) values (11)
    insert into #t2 (data) values (12)
    insert into #t2 (data) values (13)
    insert into #t2 (data) values (14)
    insert into #t2 (data) values (15)
    insert into #t2 (data) values (16)
    
    select * from #t2
    
    ROLLBACK
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Double has range more than a 64-bit integer, but its precision is less dues
Bit confused here, I have an on-demand instance but do I get charged even
200,000,000 is much less than the maximum 32-bit INTEGER, 2,147,483,647.
Bit of a strange question here i know. but i wanted to know if
Bit support question. Apologies for that. I have an application linked with GNU readline.
Bit of a philosophical question. If you have a public website with a site
Bit of an odd question but is there a way of seeing what objects
Bit of a bizarre question, but does anyone know the actual limit to the
Bit of a beginner question here: Say I have a block of xml: <root>
From my experience with Windows 7 (64-bit) and Java, a 32-bit JRE uses less

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.