Click here to Skip to main content
14,826,929 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using vs 2008 and sql server. Problem is whenever i insert a new record in a table, it is inserted but auto increment value skips the number. Any solution plz?
ArunRajendra 7-Nov-13 0:47am
What do mean by skip? is it inserting 1,3,5 etc?
Pankaj Mahor 7-Nov-13 0:52am
Gopi Kishan Mariyala 7-Nov-13 0:53am
Are you using identity column for the primary key in your table. After insertion are you returning the inserted row id. Can you show us the code that you have written to insert the record
Prasad Khandekar 7-Nov-13 0:55am
Please check the definition for your IDENTITY Column it should be of form IDENTITY [ (seed , increment) ]. So for number to start from 1 and increment by 1 it will e IDENTITY(1, 1). Please also note that a transaction inserting multiple rows is not guaranteed to get consecutive values for the rows because other concurrent inserts might occur on the table. If values must be consecutive then the transaction should use an exclusive lock on the table or use the SERIALIZABLE isolation level.

Thanks7872 7-Nov-13 0:58am
This should be posted as a solution. My virtual +5 :-)
Pankaj Mahor 7-Nov-13 1:06am
I have id column with primary key and auto increment. If i delete a row and then insert a new record, it is then incrementing like 1, 2,..10, 12,13...
♥…ЯҠ…♥ 7-Nov-13 3:16am
Have a practice to post question as much as clear because no one can read your mind and suggest solution for that.

1 solution

I reckon, the so called problem is

You have inserted 3 records initially like

ID Name Value
1 RK 100
2 Karthick 200
3 Prabakar 300

You have deleted ID 2 and 3 from the table,

now you are inserting another set of records like

Mani 400
Kaajal 500

into the table, now it is inserted as

4 Mani 400
5 Kaajal 500

Final table content would be like this

ID Name Value
1 RK 100
4 Mani 400
5 Kaajal 500

If am right then this is not a problem in sql server,then you should refer this link[^]
Hope this could help you a bit.

Pankaj Mahor 7-Nov-13 1:09am
Yes, i have exactly this problem.
Pankaj Mahor 7-Nov-13 1:10am
Thanx for the link, it helped me.
♥…ЯҠ…♥ 7-Nov-13 1:13am
Happy to hear that, try to mark it as answer.... ;-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900