Reset Primary Key

  • Thread starter Thread starter scotttt
  • Start date Start date
S

scotttt

Guest
Hi all,

Ive written a program in .net and am currently using an access db as the backend.
In the db I had 200 test records which i deleted to get the db ready for deployment. When i add a new record now the primary key on my "booking" table carries on from the old test number so 201.

Can I resest this so it starts back at #1 as once the db gets updated, the program i wrote then takes the data and updates the accounting system and uses the primary key as the invoice number and so I would like to start at 1.

Thanks in advance

Scott
 
hello scotty's (scott-t's) :)

quick tip: be sure to check out the search function on these forums. there are plenty of posts on this subject. :)

off the top of my head, i think one possibility is to import your objects into a new database. or, copy your table without a PK then add a PK (auto-num) after. something like that. search for other options if those don't do it, or post back.
 
Last edited:
Cheers for the reply,
Your right i should have searched but had 5 mins before i had to go out - sorry!

Deleted the PK in table, saved table as new, put PK back in, deleted old table, renamed new table to old name and all is fine.

Cheers

Scott
 
Bear in mind though that Autonumbers can 'lose' numbers in the sequence if a record has been started but canceled (or PC crashes :( ).
Autonumbers are really designed to provide a unique pimary field and are not good for real world numbering.

Peter
 
I agree with Peter, you should maybe add 1 to the Max of a non Autonumber.

But in answer to your original question, compacting the Access backend will reset the number to the next highest in the sequence. In your case 1 as you deleted the records.
 
The actual "value" of the autonumber should have no significance to the record other than providing a unique key value to current record. The autonumber value should not be made known to the user since it should have no true significance to the record.
 

Users who are viewing this thread

Back
Top Bottom