Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
When to allocate primary key value?
Message
From
10/10/2004 04:17:25
 
 
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:
00950225
Views:
15
Hi Alan - IMO, it can make perfect sense to retrieve a new PK value in advance, e.g. using the control table AKA Tastrade NewID() approach you mentioned or with the CoCreateGUID() API. I'm doing so too in most cases.

my 2 cents
-Stefan

>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
Previous
Reply
Map
View

Click here to load this message in the networking platform