Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create a auto-number field ?
Message
From
21/12/1998 07:50:00
 
 
To
20/12/1998 22:55:32
Tran Ba Tuyen
Institut of Information Technology
Ho Chi Minh City, Vietnam
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00169289
Message ID:
00169319
Views:
21
>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?)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform