【问题标题】:How to design database to store attributes of attributes into database如何设计数据库以将属性的属性存储到数据库中
【发布时间】:2014-08-14 17:48:05
【问题描述】:

我正在为珠宝网站设计数据库,其中将存储很多产品。在为产品属性设计表格时,我卡住了。我的问题是如何在数据库中存储产品属性和子属性等。

到目前为止,我已经为产品和属性创建了 3 个表 -

  1. tbl_attribute

    Structure: attribute_id*, attribute_name
    
  2. tbl_products

    Structure: product_id*, category_id(FK), product_name, seo, description, metatags, length, width, height, weight, image, status
    
  3. tbl_products_attribute

    Structure: product_id(fk), attribute_id(fk), value
    

我有一个情况假设项链有 5 个石头(石头是属性),每个石头都有以下子属性 1.石头名称 2.石头颜色 3.石材处理方法 4. 石材清除 5.石头形状 6. 石材价格

等等等等……我有这么多属性,比如石头,所以请你帮我设计一下这些属性的表格。

取决于我必须在前端搜索(过滤器 || 分面搜索)产品的属性。

点赞:www.firemountaingems.com


详细属性和子属性列表:

Alphabatical
Availability (Sold Individualy, Sold in Bulk)
Birth Stone
Brands
Color (red, green, blue)
Design Type
Gender (Male, Female)
Images 
Karat (18k, 22k, 24k)
Link
Make (Hand, Machine, Oxidised)
Making Percent
Material Type (Leather, Gemstone, etc)
Metal Art
Metal Stamp
Metal Type (Gold, Silver, PLatinum etc)
Model
Name
Price
Purity
Shapes (round, oval, emerald, diamond etc)
Short Description
Sides (single, both,)
Size (small, big etc)
Special Price
Status
Stone (Name, Color, Treated Method, Clearity, Shape, Price, Main Stone Color (Red, Pink, Green))
Stringing Material
Warranty
Wastage Percent
Weight
Wire - Wrapping Wire

到目前为止,我已经在网上搜索了很多教程和文章以及堆栈溢出。

非常感谢您的帮助。

【问题讨论】:

    标签: mysql database-design


    【解决方案1】:

    在这种情况下,您无法创建这样的表,最好的方法是只有 1 个产品表和 1 个属性表,它们将具有产品的所有属性,但具有列属性级别和父 ID,其中父 ID 指的是同一表的 ID。

    示例: 产品表:

    ID | Name
    ----------
    1  | Necklace
    
    
    ID | ParentID | AttributeName | ProductID | AttributeLevel | AttributeDescription
    ----------------------------------------------------------------------------------
    1  |          | Stone         | 1         | 1              | stone description in general
    2  | 1        | StoneName     | 1         | 2              | Ruby 
    

    通过这种方式,您可以在一个表中对属性级别进行分级。

    【讨论】:

    • 尊敬的伊玛目,我理解您要解释的内容,这对我来说非常有帮助,我喜欢它,但我有一个疑问,我将如何根据属性和子搜索产品属性。我必须根据类别、金属、形状、颜色、价格等众多属性来过滤产品。
    • @HappySingh 我建议使用 1 个表来保存所有级别属性(属性、子属性等)的信息,其中将 ID 作为主键,然后为其子属性设置 id在它的 parentID 中,它会起作用。
    • 假设您是否必须搜索具有黑色的产品。现在您使用我的方法在其搜索查询中看到什么问题,其中每个属性都有其 productid 并且链接到它具有 parentid 的所有父属性子属性也一样。
    • 对于stone1,您可以将属性存储在BIGText类型的1列中,由'|'分隔即 Ruby|Red|square 并且您可以使用 like 运算符查询此列现在假设您要搜索红色红宝石,但仅对于价格,您需要添加单独的列,因为用户可能有兴趣搜索宝石
    • 在单个列中存储多个值... 太糟糕了。 :(
    猜你喜欢
    • 1970-01-01
    • 2011-11-17
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 2015-06-27
    • 2017-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多