Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
When to allocate primary key value?
Message
 
To
09/10/2004 20:23:30
Alan Harris-Reid
Baseline Data Services
Devon, United Kingdom
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00950209
Message ID:
00950267
Views:
12
>I have encountered a problem with my application framework and would appreciate input from other developers before deciding which way to go.
>
>When allocating a unique identifier (or primary key, usually an integer value) to each new record, is it better to allocate a) immediately the record is created, or b) just before the new record is comitted to the table (eg. using TABLEUPDATE())?
>
>As I see it, with method a) new child records can be added in same 'add' session, and have a parent id value that can be assigned immediately without having to save the parent record first. However, if the new record (perhaps child records as well) is discarded before saving, there will be a gap in the allocated number sequence (not that important IMO). Are there any pros/cons that I need to consider?
>
>For the record I do not use the autoincrement feature in VFP8, I get the next available id for a particular field via a separate control table.
>
>I would be interested to hear how other developers approach this issue.
>
>Many thanks,

Alan,

I'd use the auto-increment method for the PK. If you need to know the next value prior to inserting the record, AFIELDS() can be used to retrieve it. Look at the help for this, you'll see that the 17th column in the array returns this value.
George

Ubi caritas et amor, deus ibi est
Previous
Reply
Map
View

Click here to load this message in the networking platform