| Subject |
Re: creating unique key : usingprimair key and foreign key |
| From |
Ken Mayer <dbase@nospam.goldenstag.net> |
| Date |
Wed, 3 Feb 2021 10:09:25 -0800 |
| Newsgroups |
dbase.getting-started |
On 2/3/2021 9:59 AM, Mervyn Bick wrote:
> On 2021/02/03 18:57, Akshat Kapoor wrote:
>
>> I need some more info before I can give a confirmed suggestion.
>> Are you using dbf tables or some other backend database system.
>>
>> If you are using level 7 dbf tables then you have a field type called
>> autoincrement. Most of the backend database systems support this in
>> some way or the other.
>>
>> If you use autoincrement then the unique number generation routine is
>> not required.
>>
>> I think you should type
>> help masterRowset
>> in your command window and press enter.
>>
>> It should guide you how to display rows in child tables that are
>> linked to the current row in main table.
>
> As I understand it Dirk's problem is not in displaying the data but
> getting the correct primary key in the main table to use as a foreign
> key in the child table.
>
> 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.
One thing to keep in mind, if you have the parent/child relationship set
up correctly in dBASE, when you append a child record, it SHOULD
automatically be inserting the primary key for the parent record into
the child record for the foreign key needed for the link between the
table. This needs to be done using the rowset object's masterRowset,
masterFields, and so on. This is covered in my books with examples.
Ken
--
*Ken Mayer*
Ken's dBASE Page: http://www.goldenstag.net/dbase
The dUFLP: http://www.goldenstag.net/dbase/index.htm#duflp
dBASE Books: http://www.goldenstag.net/dbase/Books/dBASEBooks.htm
dBASE Tutorial: http://www.goldenstag.net/dbase/Tutorial/00_Preface.htm
|
|