Marcelo
I use surogate keys for this very reason - that you never have to change
them an the join condition
detewwn a master and detail is one field - this does not prevent you from
add extra 'unique' indexes to
enforce ID uniqueness. ie for your invoice tables PK is InvoiceID (use a
generator under IB)
but you may also have a non null field invoice_number which has a unique
index
You may then add the year to the invoice Table and not have to alter the
relationship
ie
CREATE TABLE Invoice
(
InvoiceID INTEGER NOT NULL,
Invoice_Number CHAR(10) NOT NULL,
CONSTRAINT PK_Invoice PRIMARY KEY (InvoiceID)
)
CREATE UNIQUE INDEX Idx502 ON Invoice (Invoice_Number)
CREATE TABLE InvoiceDetail
(
InvoiceDetailID INTEGER NOT NULL,
InvoiceID INTEGER NOT NULL,
CONSTRAINT PK_InvoiceDetail PRIMARY KEY (InvoiceDetailID)
)
ALTER TABLE InvoiceDetail
ADD CONSTRAINT Relation_200 FOREIGN KEY
( InvoiceID )
REFERENCES Invoice
( InvoiceID )
----- Original Message -----
From: Marcelo Miorelli <[EMAIL PROTECTED]>
To: Multiple recipients of list delphi <[EMAIL PROTECTED]>
Sent: Friday, 6 October 2000 02:09
Subject: [DUG]: Keys in Interbase
> Untitled-1
> Dear friends of Interbase list or Delphi list,
>
> I have an interesting proposition, that I think would be instructive for
> everyone.
> It's about databases in general and specially interbase, if there might be
> any difference.
>
> The question is that I have got an Invoice table that has as primary key two
> fields, invoice_serial, and invoice_number.
> But due to the great amount of invoices, and having the obligation to keep
> them at least the last five years, I have been thinking about to insert
> another field into the primary key, which would be invoice_year.
> So the primary key in the master table and in the detail table (for the
> itens of the invoice) would be invoice_year, invoice_serial, and
> invoice_number. For the detail
table another attribute is code_product.
>
> This information is an extremely valuable asset for everyone working with
> any database.
> I hope not to have disturbed anyone with my message.
>
> Your well-wisher and friend on the list,
> marcelo miorelli
> [EMAIL PROTECTED]
>
>
> --------------------------------------------------------------------------
-
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"