简体   繁体   English

如何设计数据库以将属性的属性存储到数据库中

[英]How to design database to store attributes of attributes into database

I am designing database for jewellery website in which a lot of products will store. 我正在为珠宝网站设计数据库,其中将存储许多产品。 While designing tables for attributes of products i stuck. 在设计产品属性表时,我遇到了麻烦。 My problem is how store product attributes and there sub attributes and so on in database. 我的问题是如何在数据库中存储产品属性以及子属性等等。

Up to now i have created 3 tables for product and attributes - 到目前为止,我已经为产品和属性创建了3个表格-

  1. tbl_attribute tbl_attribute

     Structure: attribute_id*, attribute_name 
  2. tbl_products tbl_products

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

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

I have a situation suppose Necklace have 5 stones (Stone is attribute) and each stones have following sub attributes 1. Stone Name 2. Stone Color 3. Stone Treated Method 4. Stone Clearity 5. Stone Shape 6. Stone Price 我有一种情况,假设项链有5个宝石(宝石是属性),每个宝石都有以下子属性:1.宝石名称2.宝石颜色3.宝石处理方法4.宝石净度5.宝石形状6.宝石价格

and so on etc.... and i have So many attributes like stone so can you please help me how to design the table for these attributes. 等等等等。。。我有很多属性,例如石头,所以请您帮我设计一下这些属性的表格。

Depends on that attributes i have to search(FILTER || Faceted Search) the products in front end. 取决于该属性,我必须在前端搜索(过滤器||分面搜索)产品。

Like: www.firemountaingems.com 喜欢: www.firemountaingems.com


Detailed attributes and sub attributes list: 详细属性和子属性列表:

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

Up to now i have search so many tutorials and article on net as well as on stack overflow. 到目前为止,我在网上以及堆栈溢出中搜索了如此多的教程和文章。

Your help is highly appreciated. 非常感谢您的帮助。

In this case you cant afford creating tables like this the best approach is to have only 1 product table and 1 attributes table which will be having all attributes of a product but with columns attribute_level and parent_id where parent_id refers id of same table. 在这种情况下,您不能像这样创建表,最好的方法是只有1个产品表和1个属性表,这些表将具有产品的所有属性,但具有attribute_level和parent_id列,其中parent_id表示同一表的ID。

Example: products table: 示例:产品表:

ID | Name
----------
1  | Necklace


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

In this way you can make hirerchy of attribute levels within one table. 通过这种方式,您可以使一个表中的属性级别更加混乱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM