Link to home
Create AccountLog 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
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
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
Create an account to see this answer
Signing up is free. No credit card required.
Create Account