>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