0

hi guys, im using microsoft c# along with sql server 2k8 to build my database software, i have 2 problems..

1st is i cant seem to make an incrementing primary key that doesnt start with 1?
i wanted to make my primary key start from 00001 then increment it by 1 but it only allows me to start from 1 and increment by 1.

2nd problem is, when i delete rows in my database using my c# program, it works but when i add new rows, it still remembers the primary key of the row i deleted then it skips the primary key and uses the next number..
Example if this is when i delete a row with primary key of 4. then add a new row, it automatically creates a row with primary key of 5 instead of 4. can i fix this? thanks

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by dickersonka
0

If you have an auto incrementing number, you've just described exactly what it is supposed to do, it does not reuse numbers. If you want it to fill in the holes, then you would need to not use an auto increment, and do a routine that works out the holes in your numbers list to find which numbers it can put in.

As for the key being 000001, that comes down to formatting.

Neither of these is specific to c# or SQL 2008

0

set identity seed to be able to change the 1 to a different number

the padding with 0's is formatting, do it code side or in query, not store numbers in a database like that

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.