Subject Re: creating unique key : usingprimair key and foreign key
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Tue, 9 Feb 2021 11:29:25 +0530
Newsgroups dbase.getting-started

Good Morning Alex,


> Thanks Akshat -- I didn't understand that the issue was creating a new record with SQL. Yes, with INSERT the record is created and if there is an autoinc field there will be a unique number created. But what is the number and where is the record? As you and Mervyn say, in a multi-user environment the number is not known and the record is not necessarily the last one in the table. It's kind of like the problem of creating unique account numbers in VdB 5.x witiout using seqvalue -- the alternative of going to the bottom of the table to find the supposedly latest account number and adding one to it is not reliable for the same reason.
>
> But with beginappend() once you save, you're sitting on the new record, and you can certainly know what the new autoinc number is.

Yes.
form.rowset.fields["autoinc_fieldname"].value is sufficient
Provided you have not performed any requery() or navigation or any other
operation like applylocate etc which cause implicit navigation.
If you navigate the value is lost and there is no way of retrieving it.

>
> As Ken and Robbie said, if you use INSERT in a web app you will have to do some work to try to find the right record.

Most backend databases function through sql. So to counter the above
problem they provide a function that will return the primary key value
of the row LAST inserted by that database object.

If for some reason you disconnect with the database or perform another
insert the value cannot be retrieved.

Hence take care.
Regards
Akshat