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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
If you have repeated data in multiple tables, you run the risk of having data that is inconsistent between the tables.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?