Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What should the primary key be?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00182646
Message ID:
00182654
Vues:
22
Vic,

Yes, as a rule it is generally NOT advisable to use a field that has a business purpose as your primary key index expression (like an account #, etc.). It is better to use a separate field that has no business value as your primary key (preferably of type integer or numeric).

The reason why you should do this is because you may need to change the value of your business key (i.e. account #) and that leaves you with a referential integrity headache if it serves as the link to another table. If you use a surrogate key instead (any key field that does not have any business value), you won't need to worry about ever having this happen because you'll never need to change it.

I like to create primary keys that are of type integer and then I just increment the value (stored in another table with the table name as the lookup key) and replace it in the newly added record. This routine can reside in a utility PRG or even a stored procedure (or in your application object).

I hope this helps.

Regards,

-JT
Jeff Trockman, MCP
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform