Jump to content
  • Announcements

    • alpenwasser

      Please Use CODE Tags   31 Jan 2016

      Welcome to the Programming and Software Design Section,

      When asking for help with programming issues, please use the code tags to enclose your code, it makes things much more easily readable for the people trying to help you, thus improving your chances of actually getting help.
        To add code tags, click the <> button on the editor toolbar, then enter your code in the code editor that appears. If you are on a mobile device, or prefer to use BBCode, you can use [code] // Your code here // It will be syntax highlighted, though not necessarily corectly. [/code] (but the code editor is more consistent and less buggy).
Shammikit

SQL server auto increment ID problem

Recommended Posts

Posted · Original PosterOP

i have a column called ID in my table and i have set it to increase by 1 when new data is inserted. when i inserted data like 3 times the ID was 3 but when i added another record instead of showing the ID as 4 it showed 6. i checked my auto increment settings and it was set to increase by 1. i didnt understand what was happening so i dropped the table, made a new one and started entering data. the first time i entered the ID was one but the second time i inserted it showed 4 as ID and the third time in inserted a record ID was 6. what is actually going on? im inserting data using the edit table data mode in sql server however the first time i tried it was using C# and i got the same issue. is this some error in sql server 2014 or am i doing something wrong?

21.JPG

Capture.JPG

Link to post
Share on other sites

did you delete any rows? The database auto interment keeps a track of them.

 

1. Data

2. Data

3. Data

del 3, 2

4. Data

 

at the end the ids would be 1,4

 


                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites
Posted · Original PosterOP
13 minutes ago, vorticalbox said:

did you delete any rows? The database auto interment keeps a track of them.

 

1. Data

2. Data

3. Data

del 3, 2

4. Data

 

at the end the ids would be 1,4

 

no, i inserted only and it came like that.

Link to post
Share on other sites
Posted · Original PosterOP
Just now, Lumi said:

I don't see why this is even an issue. It's probably because you removed some rows. SQL keeps track and continues the increment.

i didnt remove any. when i added a new row the ID automatically generated to that shown in the images.it happened twice now.thats why i decided to ask here

Link to post
Share on other sites
51 minutes ago, Shammikit said:

i didnt remove any. when i added a new row the ID automatically generated to that shown in the images.it happened twice now.thats why i decided to ask here

Then not a clue, but if its not going to break a system, which it shouldn't I wouldn't worry ti much. 


                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites
Posted · Original PosterOP
Just now, vorticalbox said:

Then not a clue, but if its not going to break a system, which it shouldn't I wouldn't worry ti much. 

i want to use that ID for a calculation and if they r not in correct numbers i will have trouble displaying the next record in my application

Link to post
Share on other sites
6 minutes ago, Shammikit said:

i want to use that ID for a calculation and if they r not in correct numbers i will have trouble displaying the next record in my application

maybe you should find a new way then, as said the auto increment doesnt always have the last number but the last number of record.

 


                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites
2 hours ago, Shammikit said:

i didnt remove any. when i added a new row the ID automatically generated to that shown in the images.it happened twice now.thats why i decided to ask here

Is your insert in a loop that closes and reopens the connection by chance?


i want to die

Link to post
Share on other sites
Just now, Shammikit said:

no it isnt. i have tried inserting manually from sql server, it still happens

oh well dont fix whats not broken


i want to die

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

×