9

データベース設計は初めてです。cms の製品属性データベース設計のより良いオプションは何ですか?(他のオプションも提案してください)。

オプション 1: 1 テーブル

products{
id
product_name
color
price
attribute_name1
attribute_value1
attribute_name2
attribute_value2
attribute_name3
attribute_value3
}

オプション 2: 3 つのテーブル

products{
id
product_name
color
price
}

attribute{
id
name
value
}

products_attribute{
products_id
attribute_id
}
4

4 に答える 4

30

You're making a common mistake of database design, storing name in one column and value in another column. This is not a relational database design.

Each attribute should be named by the column name. Color, pages, shirt size, publish date, should be column names.

If each product type has a distinct set of attributes, there are other solutions. See my answers to:

Also please read this story: Bad CaRMa: Introducing Vision before you implement a database designed around name-value pairs as you are doing.

于 2010-05-31T17:41:31.323 に答える
4

あなたが得ることができる製品属性の最良の実装は

Product_Tbl [
    ID
    Name
    more columns
]

Attribute_Tbl [
   ID
   Att_Name
]

Product_Attribute_Tbl [
    Product_ID
    Attribute_ID
    Value
]

製品に同じ属性がない場合は、この構造を使用できます

于 2011-10-18T18:09:19.440 に答える
1

それはあなたがあなたのデータベースから何を望むかに依存します。すべての製品が同じタイプで同じ属性を持っている場合は、次のようなことを行う必要があります。

products {id:integer、product_name:string、color:string、attribute_name1:string、attribute_name2:string...}。Attribute_name {}は、「color」(これも属性です)のように、意味のある単語である必要があります。

于 2010-05-31T17:32:48.813 に答える