Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best way to generate key field values
Message
De
23/07/1998 10:28:23
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
23/07/1998 10:07:03
Mandy Mccord
Public Interest Breakthroughs, Inc.
Albany, New York, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00120429
Message ID:
00120447
Vues:
19
>Just curious what folks think out there regarding what's the best way to generate key field values when adding new records to tables.
>
>When my users click the ADD button, I've been running code to use the table in the key field order, go bottom, find the last value and add 1 to it for the new record's key field value.
>
>It seems to be working fine, though I realized I had to play with my SET DELETED ON/OFF commands so my next value was unique and not the same as a deleted record's.
>
>I know some folks keep separate tables to track the next available key value for their tables. I'm assuming it looks like a 2 field table, one for the table's name, one for the next value. You'd then check there for the next value you want to assign.
>
>Any way better than any other??
>
>MTIA!!
>
>Mandy
Mandy,
For your case to work you should be using unbuffered tables, still yet w/o locking records you might get same value for different users in a multiuser environment. If you are not using buffering then directly using recno() is better I think.
I also don't keep another table but my way is slightly different. I keep pcode and ccode fields for every table I create. Set their default value as :
pcode : iif(used("ParentTable"),ParentTable.ccode,sys(2015)+sys(2007,sys(0)))
* For top parent nothing
ccode : sys(2015)+sys(2007,sys(0))
Well long 15 char id fields, yes, but I live them w/o no performance loss and no headache. I like to control it DBC level because always there is risk someone (me) could hack with them outside my app. Space loss is far more than using integer keys but I don't know, I just feel happy with this for the moment.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform