Re: do all primary keys use autonumber

Tech-Archive recommends: Fix windows errors by optimizing your registry



k wrote:

do all primary keys use autonumber

(Point of netiquette: It's considered good form to put your actual question into the body of a message.)


No, of course they don't. But Autonumber is a convenient way to be sure that you won't have any duplicate values, and an Autonumber field occupies only about 4 bytes per record, much shorter than many other fields you might choose to use.

Your primary key could even consist of more than one field, for example using both [First Name] and [Last Name] (assuming you don't have two people named "Mary Jones").

If you don't use Autonumber, you'll need to get your key values from somewhere, and Access is likely to complain to you if a new key value matches some existing one, as they must be unique in the Table. In such a case, you'll need to choose some other value, and if you were trying to enter a name, you will have to modify it somehow, such as by changing "Mary" to "Mary_1".

To avoid confusing my Autonumber values with something meaningful (such as people's ages), I usually set the "New Values" property of the field to Random, making it obvious that they're keys.

  -- Vincent Johns <vjohns@xxxxxxxxxxxxxxxxxx>
  Please feel free to quote anything I say here.


.



Relevant Pages

  • Re: Corrupted DB, now problems entering data
    ... Have you installed the bug fixes and patches from Microsoft? ... like the autonumber fiasco, you are using something for the wrong use. ... That new window shows ... > index to permit duplicate entries and try again. ...
    (microsoft.public.access.gettingstarted)
  • Re: Copy/Paste Records with Multiple Subform Records
    ... Use a combination of DAO and SQL. ... Duplicate the main record with AddNew to the form's RecordsetClone. ... You can now get the new autonumber. ... form record, but the value for the foreign key will be the new autonumber ...
    (microsoft.public.access.formscoding)
  • Re: Allen Brownes Copying forms/Subforms
    ... perhaps the duplicate is on another field where you specified a "No ... Presumably you are not assigning a value to the OrderID. ... If it is not the autonumber, open the table in design view, and open the ... would create duplicate values in the index, primary key, or relationship. ...
    (microsoft.public.access.modulesdaovba)
  • Duplicating record in mainform, subform and sub-subform
    ... to duplicate the records for a sub-subform. ... They relate one to many through Autonumber an autonumber field assigned by ... the 1 Printing Price table and there could be as many as nine Autonumber ... Printing Price into Calcs, not the Autonumber from the original Calcs table ...
    (microsoft.public.access.formscoding)
  • DMax
    ... trapping to deal with a duplicate assignment so you can ... custom solution is FAR WORSE than the autonumber solution. ... >in increments of 1, a record such as a box number within ... >It has been suggested that I use the DMax function, ...
    (microsoft.public.access.forms)