According to database theory you should never store the same data twice. I want to present 1 scenario and explain my undertanding of design and I hope then someone can point out my errors if there are any.
*********************************************************
Current Scenario: Suppose you have
OrderDetails Table is related (Referential integrity and both cascades) to the OrderHeader table and has the following fields.
LineID, OrderNum, InvoiceNum, Description, NumberUnits, UnitPrice, WasteClass,
..... and suppose you have
InvoiceDetails table which has the same fields as above but is related to the InvoiceHeader table (RE and Both Cascades)
This design is no good because InvoiceDetails stores the same info as OrdersDetails.
To solve this
1. Get rid of the the InvoiceDetails table and create a relationship between InvoiceHeader and OrderDetails with the InvoiceNum fields. This relationship can only have Referential Integrity and Update Cascades but No delete Cascades.
2. The original relationship between Orderheader and OrderDetails remains the same.
3. When we delete an Invoice we must programatically set the InvoiceNumber field in the OrdersDetail records to Null.
4. When an OrderDetail has an invoice Number associated with it we must lock it from further changes in the Orders Form.
5. The OrderDetail can be unlocked for changes in the Invoice form.
Is this good design? Any errors or suggestions. Seems a bit odd to design this way at first but I can see the power in this. This design completely eliminates updates between the InvoiceDetails and OrderDetails tables.
Also it saves tons of space cause the InvoiceDetails table is gone.
I currently have a much more difficult scenario and I can't figure out how to normalize it but I want to make sure the above is correct.
Thanks.
*********************************************************
Current Scenario: Suppose you have
OrderDetails Table is related (Referential integrity and both cascades) to the OrderHeader table and has the following fields.
LineID, OrderNum, InvoiceNum, Description, NumberUnits, UnitPrice, WasteClass,
..... and suppose you have
InvoiceDetails table which has the same fields as above but is related to the InvoiceHeader table (RE and Both Cascades)
This design is no good because InvoiceDetails stores the same info as OrdersDetails.
To solve this
1. Get rid of the the InvoiceDetails table and create a relationship between InvoiceHeader and OrderDetails with the InvoiceNum fields. This relationship can only have Referential Integrity and Update Cascades but No delete Cascades.
2. The original relationship between Orderheader and OrderDetails remains the same.
3. When we delete an Invoice we must programatically set the InvoiceNumber field in the OrdersDetail records to Null.
4. When an OrderDetail has an invoice Number associated with it we must lock it from further changes in the Orders Form.
5. The OrderDetail can be unlocked for changes in the Invoice form.
Is this good design? Any errors or suggestions. Seems a bit odd to design this way at first but I can see the power in this. This design completely eliminates updates between the InvoiceDetails and OrderDetails tables.
Also it saves tons of space cause the InvoiceDetails table is gone.
I currently have a much more difficult scenario and I can't figure out how to normalize it but I want to make sure the above is correct.
Thanks.