Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What should the primary key be?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00182646
Message ID:
00182654
Views:
20
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
Previous
Reply
Map
View

Click here to load this message in the networking platform