General information
Category:
Coding, syntax & commands
>>I want to have a auto-number field in the multi-user environment.
>>I frequently use table buffering in my input forms.
>>How to eliminate duplicate key when inputting ?
>
>I do it this way:
>
>1. I use INTEGER keys wherever possible.
>
>2. I have a table (LASTKEY) with just one record, holding (surprise!) the last used key number.
>
>3. I wrote a function (GETNEXTKEY) which opens LASTKEY EXCLUSIVEly, increments the last key number, and returns that value. (Don't forget to close the table, or you will cause quite a deadlock!)
>
>4. I specify GETNEXTKEY() as the default value for all key fields.
>
>Note: it's OK to share the same LASTKEY for all tables, since with INTEGER fields you have more than 2 billion possible key values, and that allows me not to worry about unused key values either. (If the user starts to insert a new record but cancels it, a key value will go unused. So what?)
There is an example in the TASTRADE application (which was in vfp3, but I haven't seen vfp6 yet). You'll see a table named "keys" and a stored procedure named "newid". This example uses separate records for the keys to separate tables.
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only