[Lazarus] FPReport file names

Michael Van Canneyt michael at freepascal.org
Wed Sep 13 22:23:54 CEST 2017



On Wed, 13 Sep 2017, Ondrej Pokorny via Lazarus wrote:

> On 13.09.2017 20:33, Graeme Geldenhuys via Lazarus wrote:
>> On 2017-09-13 19:17, Michael Van Canneyt via Lazarus wrote:
>>> Similarly, every field in a database I create is always uniquely named.
>>> So if I ask "where is field TX_ID' I get exactly 1 field, in 1 table.
>>> Graeme Geldenhuys can testify that I use this practice even in very 
>>> big databases.
>>
>> I can confirm that. :)
>
> Huh, that's hardcore :)
>
> Just curious: how do you define foreign keys? E.g.
> Customers.ID
> Invoices.CustomerID
> Orders.CustomerID

create table customer (
   C_ID INT Primary key,
   C_FIRSTNAME VARCHAR(30),
   C_LASTNAME VARCHAR(50)
);

CREATE table invoice (
   I_ID INT PRIMARY KEY,
   I_CUSTOMER_FK INT,
   I_DATE DATE
);

ALTER TABLE INVOICE ADD CONSTRAINT R_INVOICE_CUSTOMER FOREIGN KEY (I_CUSTOMER_FK) REFERENCES CUSTOMER(C_ID) ON CASCADE DELETE;

3 "rules" :
Prefix is always somehow related to table name. Usually 1 or 2 letters.
Occasionaly 3 (if you have close to 600 tables, 2 letters doesn't always cut it)

Primary key is always Prefix_ID
Foreign key is always Prefix_FOREIGNTABLE_FK

The SQL you construct like this is always unambiguous, unless you use the
same table twice in a single SQL select there is never any need to prefix
the fields with the table name.

Michael.


More information about the Lazarus mailing list