Scott Klarenbach wrote:
> These are the tables in question:
> RFQ (Request for Quote)
> Inventory items ALWAYS have a partID.
> RFQ items ALWAYS have a partID.
> However, sometimes, RFQ items have an inventoryID as well. Now, we have a
> redundancy problem. Because, in those instances when the RFQ has an
> inventoryID, the partID should be derived from the inventoryID. If there is
> no inventoryID, then the partID needs to be stored directly in the RFQ
> table. We don't want to have both the inventoryID and the partID in the RFQ
> table, because it opens up data integrity issues. ie, what if the RFQ item
> shows inventoryID 2, and partID 1...but inventoryID 2 is associated to
> partID 2. Now which partID is correct? They can't both be right.
Since there have not been a lot of responses I decided to jump in. It
sounds to me like we have real-world object behavior mixed up with the
data model. Example "RFQ items ALWAYS have a partID .... If there is no
inventoryID, then the partID needs to be stored directly in the RFQ
table." Why? Who or what is enforcing this?
Can we look at overall object behavior, then come up with a model that
supports the behavior with no preconceptions of table structure.
I assume that an RFQ item is a document (paper or eletronic). What does
one look like? From your description it will always have a partID and
may have an inventoryID. Who populates these fields? Why is there a
redundancy in the first place? Who checks to see that the "direct"
partID matches the "derived" partID?
How about leaving partID and inventoryID out of the RFQ table, and
adding an association table that relates a RFQ to either a partID or an
inventoryID. An attribute of this table would distinguish partID from an
inventoryID. Business logic would ensure that only one entry gets into
this table per RFQ, and could also validate that the "direct" partID
matches the "derived" partID
> I'm sure this type of problem is run up against all the time, and I'm
> wondering what the best practice methodology is from experienced DBA's.
> This was a simple example; however, we are running into the problem system
> wide. For example, a quote table has an OPTIONAL RFQ ID, and a mandatory
> contactID. The RFQ table has a mandatory contactID. If the quote table has
> an RFQID, we want to derive the contactID from the RFQID. If the quote has
> NO RFQID, then we need to store the contactID directly in the quote table.
> In those instances where there IS an RFQID in the quote table, we end up
> storing the contactID twice. Once in the quote table, and once in the
> association between the RFQ/Contact table. Same problem as above: integrity
> and poor overall design.
Same issue here. Remove the IDs from the quote and RFQ table and create
another association table.