Referential Intergrity Inportance

J

Jfk

Hello,

I have three tables, one for customers,one for invoices,
and one for adjustment codes.The customers table works
well for the one to many(cus)to (inv)tables but the
adjustment codes will not let me have referential
Intergrity between this table and invoice table(there can
be many codes to one invoice)Is it important to have
referential intergrity to ensure relationships?
Thanks
 
S

Steve Schapel

Jfk,

If there can be many codes per invoice, then you need another table to
manage this data, with fields such as:
AdjustmentCode
InvoiceNumber

You should be able to establish a Relationship between the Adjustment
Codes table and this other table, let's suppose it is called Invoice
Codes, based on a link between the AdjustmentCode field from both, with
Referential Integrity enforced. The RI achieves the purpose of ensuring
that you can't enter an adjustment code for an invoice if there is no
such code in the Adjustment Codes table.
 
T

Tim Ferguson

Is it important to have
referential intergrity to ensure relationships?

It depends how important it is to avoid non-existent codes on an invoice.
The point about referential integrity contraints is that they are there to
prevent garbage getting into your tables.

From a db design point of view, if there's no RI then there is no
relationship, because anything is allowed in the "fk" field.

Hope that helps

Tim F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top