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?
Microsoft SQL Server

Avatar of undefined
Last Comment
Paul Jackson

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Kevin Cross

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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?
twhaight

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
Paul Jackson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck