Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Primary key
Message
From
19/03/2003 08:34:00
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
19/03/2003 08:20:07
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00766466
Message ID:
00767475
Views:
23
>Hi,
>What about the auto-generated value? should I store it in Integer or character?
>
>Beside, should I just use the auto-generated value as forgeign key? For example in stock in table, should I place ItemCode ? Do you think place itemcode in stockin table will easier the error checking?
>
>Any comments?
>
>Thank you

My personal recommendation - many programmers use this method, and many others don't:

Use an integer, auto-generated, for the primary key of each table (or most tables). Don't show this key to the user.

If I call this the primary key, this implies that it is also used as foreign key in other tables.

For example, if you have a list of materials, each material will have a code which the user sees, and assigns - but according to the system I am recommending, this will not be the primary key. For the primary key, you will use an "auto-generated" integer, instead (before VFP 8, this would mean a separate table to store the sequences, a function to do the lookup, and call this function from the field's default value).

For other tables, use this same number as a foreign key. This might include the record of what materials come in and out, and the current stock (if you need to keep track of more than one warehouse).

Greetings,

Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform