in Education by
This is a scenario I've seen in multiple places over the years; I'm wondering if anyone else has run across a better solution than I have... My company sells a relatively small number of products, however the products we sell are highly specialized (i.e. in order to select a given product, a significant number of details must be provided about it). The problem is that while the amount of detail required to choose a given product is relatively constant, the kinds of details required vary greatly between products. For instance: Product X might have identifying characteristics like (hypothetically) 'Color', 'Material' 'Mean Time to Failure' but Product Y might have characteristics 'Thickness', 'Diameter' 'Power Source' The problem (one of them, anyway) in creating an order system that utilizes both Product X and Product Y is that an Order Line has to refer, at some point, to what it is "selling". Since Product X and Product Y are defined in two different tables - and denormalization of products using a wide table scheme is not an option (the product definitions are quite deep) - it's difficult to see a clear way to define the Order Line in such a way that order entry, editing and reporting are practical. Things I've Tried In the Past Create a parent table called 'Product' with columns common to Product X and Product Y, then using 'Product' as the reference for the OrderLine table, and creating a FK relationship with 'Product' as the primary side between the tables for Product X and Product Y. This basically places the 'Product' table as the parent of both OrderLine and all the disparate product tables (e.g. Products X and Y). It works fine for order entry, but causes problems with order reporting or editing since the 'Product' record has to track what kind of product it is in order to determine how to join 'Product' to its more detailed child, Product X or Product Y. Advantages: key relationships are preserved. Disadvantages: reporting, editing at the order line/product level. Create 'Product Type' and 'Product Key' columns at the Order Line level, then use some CASE logic or views to determine the customized product to which the line refers. This is similar to item (1), without the common 'Product' table. I consider it a more "quick and dirty" solution, since it completely does away with foreign keys between order lines and their product definitions. Advantages: quick solution. Disadvantages: same as item (1), plus lost RI. Homogenize the product definitions by creating a common header table and using key/value pairs for the customized attributes (OrderLine [n] <- [1] Product [1] <- [n] ProductAttribute). Advantages: key relationships are preserved; no ambiguity about product definition. Disadvantages: reporting (retrieving a list of products with their attributes, for instance), data typing of attribute values, performance (fetching product attributes, inserting or updating product attributes etc.) If anyone else has tried a different strategy with more success, I'd sure like to hear about it. Thank you. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The first solution you describe is the best if you want to maintain data integrity, and if you have relatively few product types and seldom add new product types. This is the design I'd choose in your situation. Reporting is complex only if your reports need the product-specific attributes. If your reports need only the attributes in the common Products table, it's fine. The second solution you describe is called "Polymorphic Associations" and it's no good. Your "foreign key" isn't a real foreign key, so you can't use a DRI constraint to ensure data integrity. OO polymorphism doesn't have an analog in the relational model. The third solution you describe, involving storing an attribute name as a string, is a design called "Entity-Attribute-Value" and you can tell this is a painful and expensive solution. There's no way to ensure data integrity, no way to make one attribute NOT NULL, no way to make sure a given product has a certain set of attributes. No way to restrict one attribute against a lookup table. Many types of aggregate queries become impossible to do in SQL, so you have to write lots of application code to do reports. Use the EAV design only if you must, for instance if you have an unlimited number of product types, the list of attributes may be different on every row, and your schema must accommodate new product types frequently, without code or schema changes. Another solution is "Single-Table Inheritance." This uses an extremely wide table with a column for every attribute of every product. Leave NULLs in columns that are irrelevant to the product on a given row. This effectively means you can't declare an attribute as NOT NULL (unless it's in the group common to all products). Also, most RDBMS products have a limit on the number of columns in a single table, or the overall width in bytes of a row. So you're limited in the number of product types you can represent this way. Hybrid solutions exist, for instance you can store common attributes normally, in columns, but product-specific attributes in an Entity-Attribute-Value table. Or you could store product-specific attributes in some other structured way, like XML or YAML, in a BLOB column of the Products table. But these hybrid solutions suffer because now some attributes must be fetched in a different way The ultimate solution for situations like this is to use a semantic data model, using RDF instead of a relational database. This shares some characteristics with EAV but it's much more ambitious. All metadata is stored in the same way as data, so every object is self-describing and you can query the list of attributes for a given product just as you would query data. Special products exist, such as Jena or Sesame, implementing this data model and a special query language that is different than SQL.

Related questions

0 votes
    What is the correct definition of foreign key? The common field of two tables. A field that contains unique data ... of another table. Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    What is the correct definition of foreign key? The common field of two tables. A field that contains unique data ... of another table. Select the correct answer from above options...
asked Dec 15, 2021 in Education by JackTerrance
0 votes
    Write the cartisian product of these tables and also write cardinality of resultant table after AxB:- 2 A NAME ... CRICKET 2 FOOTBALL Select the correct answer from above options...
asked Dec 19, 2021 in Education by JackTerrance
0 votes
    Write the cartisian product of these tables and also write cardinality of resultant table after AxB:- 2 A NAME ... CRICKET 2 FOOTBALL Select the correct answer from above options...
asked Dec 18, 2021 in Education by JackTerrance
0 votes
    After reading the chapter, I know these points: I know that data gets highlighted after being selected. I know ... entry and editing. Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    For a reaction, A+B→ Product, the rate law is given by r=k[A] 1 2 [B]2 . What is the order of the reactio ? Select the correct answer from above options...
asked Jan 4, 2022 in Education by JackTerrance
0 votes
    Which of the following has each related entity set has its own schema and there is an additional schema ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Which of the following has each related entity set has its own schema and there is an additional schema ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Can anyone tell me how many types of tables are there in SQL? Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
0 votes
    Suppose the user finds the usage of room number and phone number in a relational schema there is confusion ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    What are the best practices to be followed while designing a secure RESTful web service?...
asked Nov 7, 2020 in Technology by JackTerrance
0 votes
    Which type of cache reference locality aims at designing cache to store Recently Referenced Data assuming that the same ... (3)Spatial Locality (4)None of the options mentioned...
asked Oct 6, 2020 in Technology by JackTerrance
0 votes
    8)Which type of cache reference locality aims at designing cache to store the entire block near the Recently Referenced Data? (a) ... I & II (3)None of the options mentioned (4)II...
asked Oct 6, 2020 in Technology by JackTerrance
0 votes
    The process of designing a security specification and then eventually testing that specification is known as __________ ... hunting C. Threat intelligence D. Threat mitigation...
asked Feb 27, 2023 in Technology by JackTerrance
...