Link to home
Start Free TrialLog in
Avatar of printmedia
printmedia

asked on

Primary and foreign keys for SQL Server 2000 tables

Hi all.

I have 3 tables (tblFreightHeader, tblSalesOrder, tblInvoiceNumber)

tblFreightHeader: FreightHeader_ID (PK), Carrier, Weight, FreightAmount
tblSalesOrder: SalesOrder_ID (PK), FreightHeader_ID (FK), SalesOrderNumber, Customer, SalesOrderAmount
tblInvoiceNumber: InvoiceNumber_ID (PK), SalesOrder_ID (FK), InvoiceNumber, InvoiceAmount

They way it works is that there could be multiple sales order for one freightheader record. There could also be multiple invoice number for one sales order (sometimes sales orders are completed in parts i.e. various invoices).

Should I create a foreign key between tblFreightHeader and tblInvoiceNumber?
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of printmedia
printmedia

ASKER

Thanks for the reply!

So instead of doing the FreightHeader_ID foreign key between blFreightHeader and tblInvoiceNumber I can instead do the FreightHeader_ID foreign key between tblSalesOrder and tblInvoiceNumber?
In order to reduce redundancy, you should create foreign keys and normalize the data.  

If you have repeated data in multiple tables, you run the risk of having data that is inconsistent between the tables.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial