Subject Re: creating unique key : usingprimair key and foreign key
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Sat, 6 Feb 2021 12:18:20 +0530
Newsgroups dbase.getting-started

Good Morning Alex,

> Mervyn, are you saying not to use autoinc? I thought creating unique primary keys in a multiuser environment is exactly what autoinc was for. Otherwise, who needs it? What's it there for?
>
>
> Mervyn Bick Wrote:
>
>> In a multi-user system one can't guarantee that the last record in the
>> main table is the one you've just saved.  Another user may have saved a
>> record a fraction of a second after you.  SQL RDBMs make provision for
>> a programmer to get the value of the primary key of a record just saved.
>> dBASE doesn't. :-(
>>
>> The solution is not to use an autoinc field but rather use a separate
>> sequence generator.  Primary keys do not need to be in numerical order
>> in a table.  They just need to be unique.  If you want to list records
>> in the order in which they were saved add a timestamp.  Get a value
>> BEFORE saving the new parent record and use that.  There is code in the
>> dUFLP (seqval.cc) to do this.

When programming for network at times we do require primary key value of
the row we have just inserted.

Autoinc will give each row a unique value but there is NO GUARANTEE that
the last row in the table is the row you inserted. It could have been
inserted by someone else also.
So how do you get the primary key value of the row just inserted.

Mervyn is issuing a warning for that only. Because this bug in coding
will be damn difficult to debug.

Regards
Akshat