Jump to content

SQL server auto increment ID problem

Shammikit

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 comment
Share on other sites

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 comment
Share on other sites

Link to post
Share on other sites

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 comment
Share on other sites

Link to post
Share on other sites

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 want to die

Link to comment
Share on other sites

Link to post
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

Link to post
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

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 comment
Share on other sites

Link to post
Share on other sites

8 hours ago, Lumi said:

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

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

Link to comment
Share on other sites

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 comment
Share on other sites

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

×