Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Corrupted primary key
Message
De
10/07/1998 01:46:02
Larry Long
ProgRes (Programming Resources)
Georgie, États-Unis
 
 
À
09/07/1998 02:21:47
Addie Chenjin
Sd Software Co.
Tianjin, Chine
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00115591
Message ID:
00116009
Vues:
21
>hello all
>
>i found some records that had the same primary key ID in the table.
>any one can tell me why it happened and how to prevent it?
>
>thx
It is best to use a "surrogate" primary key. This means that the user never sees or has control over them. The best solution that I have found is to use SYS(2015) as the primary key. I also add an additional string to it to virtually guarantee that there will never be duplicates generated DTOS(DATE())+SYS(2015). If you have a multi-site program you can also as an ID, a two or three character key should be sufficent for most any case, to the key.

ID+DTOS(DATE())+SYS(2015) will give you an ideal solution.

When you use this key to relate to other child records, you never have to worry about the time when the user needs to "change" a code. For example, if a user sets up a customer record for "All American Air" and they are allowed a 3 char code for the customer, they may use the customer code "AAA", your primary key (build in the background might be "0119980710_REWHFYFGKH" ).

When a new customer comes along, say "American Auto Association", and they decide that they need change the old code from "AAA" to "AA1" and the new one to "AA2". With out the surrogate key, you would have to search thru all the linked tables and change them. With the surrogate key, they are allowed to change the code to whatever they wish and all the related tables still point back to the correct record.

Hope this helps!
//:^)
L.A.Long
ProgRes
lalong1@charter.net
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform