Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create a auto-number field ?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00169289
Message ID:
00169361
Views:
18
>>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
Map
View

Click here to load this message in the networking platform