Board index » delphi » AutoIncrement and Ref Integrity

AutoIncrement and Ref Integrity

I was going to use the AutoIncrement field to Generate prime keys for my
Paradox 7 tables and of course use the prime key in the table relations.
This is not allowed though.

I have experience in Clipper, FoxPro and VFP and used a function in these
languages to compress
a number into a text string for the prime key.  The next prime key Number
was stored in a special table
with struc (cTableName C 8, nNextNum N).  VFP worked nicely with the
default Field value in the DBC Database calling a Stored Procedure to get
the next Prime Key Number as a text string.

What do most Delphi programmers do for Prime Keys with Paradox tables?
Unless I am building a very small app I like to maintain an easy path to
upsize the app to Client/Server
just incase.

Thanks in advance!
--
Criston Leon Musgrave
cris...@midwest.net

 

Re:AutoIncrement and Ref Integrity


Quote
"Criston Musgrave" <cris...@midwest.net> wrote:
>I was going to use the AutoIncrement field to Generate prime keys for my
>Paradox 7 tables and of course use the prime key in the table relations.
>This is not allowed though.

You can use AutoIncrement field as primary key but DON'T DO IT. If
your table gets corrupted and you fix it your numbers are regenerated
and any links using this field are lost. If you want to use numeric
key I have seen two easy ways
- Use SQL to find MAX value of the field and increase it by one.
- Use separate table where you store one value - the highest used to
date. When you add record separate table is read incremented by one
and used as a key.

The clever people say that it is better not to use numeric key because
you can easily calculate with it in error. To use alfanumeric field
you could take either of the above use IntToStr() and add any letters
you like.

Jouko
roo00...@ceg.co.za

Re:AutoIncrement and Ref Integrity


Quote
"Criston Musgrave" <cris...@midwest.net> wrote:
>I was going to use the AutoIncrement field to Generate prime keys for my
>Paradox 7 tables and of course use the prime key in the table relations.
>This is not allowed though.

I'm only using pdx 5 files and there it works.
I use Autoinc-fields in my primary table, and integer fields in my
detail-tables.

Quote
>I have experience in Clipper, FoxPro and VFP and used a function in these
>languages to compress
>a number into a text string for the prime key.  The next prime key Number
>was stored in a special table
>with struc (cTableName C 8, nNextNum N).  VFP worked nicely with the
>default Field value in the DBC Database calling a Stored Procedure to get
>the next Prime Key Number as a text string.
>What do most Delphi programmers do for Prime Keys with Paradox tables?
>Unless I am building a very small app I like to maintain an easy path to
>upsize the app to Client/Server
>just incase.
>Thanks in advance!
>--
>Criston Leon Musgrave
>cris...@midwest.net

+-----------------------+----------------------------------+
| Henning Petersen      | mailto:hpcons...@post1.tele.dk   |
| Skoletoften 9,Blans   | mailto:oz1...@post1.tele.dk      |
| DK - 6400 Soenderborg | http://home1.inet.tele.dk/oz1lln |
+-----------------------+----------------------------------+

Re:AutoIncrement and Ref Integrity


Quote
Jouko Tolonen (roo00...@ceg.co.za) wrote:

: "Criston Musgrave" <cris...@midwest.net> wrote:

: - Use separate table where you store one value - the highest used to
: date. When you add record separate table is read incremented by one
: and used as a key.

This is, AFAIK, the only reasonably portable solution, since it doesn't
require anything but standard SQL. You should, however, make use of exclusive
locking and transaction management to ensure that only a single operation
is permitted against the sequence table at one time, or duplicate pkeys
will be created in multiuser situations.

: The clever people say that it is better not to use numeric key because
: you can easily calculate with it in error. To use alfanumeric field

Why would you want to do calculations on a primary key? Are you using
surrogate keys or are you coding values into your pkeys?

--
Ebbe Jonsson, Systems Mangler                            e...@dbm.fi
Key Systems Oy, Helsinki, Finland
Tel: +358 0 605 900, Fax: +358 0 605 991                 " Why me? "    

Other Threads