Database schema-related problem

后端 未结 2 960
旧巷少年郎
旧巷少年郎 2020-12-05 06:10

I have a kind of theoretical question about databases. To make it more concrete I have thought up an example case.

Suppose I have a store with products. I have lots

2条回答
  •  天涯浪人
    2020-12-05 06:35

    Initially I'd have suggested you have a productproperty table to model the relationship between products and properties. This would allow you to associate many products with a particular property.

    However, I'm not keen on the idea of having a value stored alongside each property as a 1:1. It might be best if you have a propertyvalue table that associates a property with a value. Then, you'd ditch the productproperty table in favour of having a richer productpropertyvalue table which could fully describe the relationship between a product, it's properties and their values.

    Perhaps then you could have the following:

    product => (ID (unique key), Name, Description)
    property => (ID (unique key), Description)
    propertyvalue => (ID (unique key), propertyID (foreign key), value)
    productpropertyvalue => (ID (unique key), productID (foreign key), propertyValueID (foreign key))
    

    Of course, property values could be complex rather than simple strings or integers, but hopefully this takes you in the right direction.

提交回复
热议问题