Hi everyone.
I'm working on a database and I've hit a difficulty I can't seem to get passed. Here is the current design:
I need to track a many to may relationship between items within an Articles table.
Basically I have Printers and Cartridges. There is a many to many relationship between them because I need to track printers/cartridges compatibility.
This is just fine. But I then need all those items available as "Articles" in order to be able to link them to an OrderDetails table for instance, or an ArticlePrices table.
So I need one row in the Articles table to indentify one row in the Printers table OR one row in the Cartridges table. A sort of "double" 1 to 1 relationship. This is difficult to enforce.
Based on what I've found on the net + a lot of thinking, here are a few solutions I could find, but all seem to be a kludge:
Is there a better solution to this problem ? I'm not conviced I have found the best solution and any input would be greatly appreciated.
I'm working on a database and I've hit a difficulty I can't seem to get passed. Here is the current design:
- tblPrinter
- PrinterID
- ArticleID
- ModelName
- tblCartridges
- CartridgeID
- ArticleID
- lkPrinterCartridgeCompatibilities (Link table)
- PrinterCartridgeCompatibilityID
- PrinterID
- CartridgeID
- Articles
- ArticleID
- MakerReferenceCode
- BrandID
- CategoryID
- lkpBrand
- BrandID
- Brand
- lkpCategory (Lookup table)
CategoryID
Category
I need to track a many to may relationship between items within an Articles table.
Basically I have Printers and Cartridges. There is a many to many relationship between them because I need to track printers/cartridges compatibility.
This is just fine. But I then need all those items available as "Articles" in order to be able to link them to an OrderDetails table for instance, or an ArticlePrices table.
So I need one row in the Articles table to indentify one row in the Printers table OR one row in the Cartridges table. A sort of "double" 1 to 1 relationship. This is difficult to enforce.
Based on what I've found on the net + a lot of thinking, here are a few solutions I could find, but all seem to be a kludge:
- Initially I wondered if GUID could help. I would update periodically printers and cartridges data, with it's GUID primary keys, to the Articles table via an UNION query. This seems pretty unreliable/dangerous though.
- Have printers have only pair primary keys, and cartridges only odd primary keys.
- Create a self referential relationship with the Articles themselves (an ArticleID is compatible with another ArticleID). This would be more work to maintain and not as flexible as printers/cartridges M to M relationship.
- Add a "Category" attribute to the Articles table (category = printer or category = cartridge). Then in the Printers table, constrain the ArticleID selection with an SQL query something like (SELECT ArticleID FROM Articles WHERE Category = 'printers') and same thing in the Cartridges table. This is the best solution I could come up with and it's the one I've implemented in the uploaded zip file.
Is there a better solution to this problem ? I'm not conviced I have found the best solution and any input would be greatly appreciated.