태그 보관물: schema

schema

변형 / 속성이 여러 개인 제품의 스키마 설계? null

MySQL을 사용하고 있습니다. 이 아이디어는 다른 개념으로 구매하는 것과 유사하므로 사용자는 여러 유형의 변형 및 속성을 가진 자신의 제품을 추가 할 것입니다.

내가 한 모든 연구에서 이것이 가장 가능성있는 해결책 인 것처럼 보이고 다음 스키마에 어떤 문제가 있는지, 그리고 어떤 단점이 있는지 궁금합니다.

감사합니다

Table: products
------------------------------
| ID | ProductName           |
|----------------------------| 
| 1  | Leather Wallet Case   |
| 2  | Jeans                 |
| 3  | Power Bank            |



Table: products_variants
-------------------------------
| ID | ProductId | ParentId | Variant  | VariantName | SKU  | StockTotal | WholeSalePrice | BuyPrice | OnSale | OnSalePrice |
|---------------------------------------------------------------------------------------------------------------------------|
| 1  | 1         | null     | model    | iPhone5     | SKU  | 10         | 3              | 10       | null   | null        |
|---------------------------------------------------------------------------------------------------------------------------| 
| 2  | 1         | null     | model    | iPhone4     | null | null       | null           | null     | null   | null        |
| 3  | 1         | 2        | color    | Red         | SKU  | 10         | 3              | 10       | null   | null        |
| 4  | 1         | 2        | color    | Blue        | SKU  | 10         | 3              | 10       | null   | null        |
|---------------------------------------------------------------------------------------------------------------------------|
| 5  | 2         | null     | size     | M           | null | null       | null           | null     | null   | null        |
| 8  | 2         | 5        | color    | Black       | SKU  | 10         | 3              | 10       | null   | null        |
| 9  | 2         | null     | size     | XXL         | SKU  | 10         | 3              | 10       | null   | null        |
| 10 | 2         | 9        | material | Cotton      | null | null       | null           | null     | null   | null        |
| 11 | 2         | 10       | color    | Red         | SKU  | 10         | 3              | 10       | null   | null        |
| 12 | 2         | 10       | color    | Blue        | SKU  | 10         | 3              | 10       | null   | null        |
| 13 | 2         | 9        | material | Casmir      | null | null       | null           | null     | null   | null        |
| 14 | 2         | 13       | color    | Green       | SKU  | 10         | 3              | 10       | null   | null        |
| 15 | 2         | 13       | color    | Brown       | SKU  | 10         | 3              | 10       | null   | null        |
|---------------------------------------------------------------------------------------------------------------------------|
| 13 | 3         | null     | null     | null        | SKU  | 10         | 3              | 10       | null   | null        |



답변

이것은 @lesandru 회신의 정보 일뿐입니다. 매우 유용하다는 것을 알았습니다. 그래서 그와 @sahalMoidu에게 크레딧

문제에 정규화를 적용하면 해결책은 다음과 같습니다. Fiddle에서 실행하고 확인하십시오.

깡깡이

CREATE TABLE products
    (
     product_id int auto_increment primary key,
     name varchar(20),
     description varchar(30)

    );

INSERT INTO products
(name, description)
VALUES
('Rug', 'A cool rug'  ),
('Cup', 'A coffee cup');

create table variants (variant_id int auto_increment primary key,
                       variant varchar(50)
                       );
insert into variants (variant)
values ('color'),('material'),('size') ;
create table variant_value(value_id int auto_increment primary key,
                           variant_id int ,
                           value varchar(50)
                           );

insert into variant_value (variant_id,value)
values (1 ,'red'),(1 ,'blue'),(1 ,'green'),
        (2 ,'wool'),(2 ,'polyester'),
        (3 ,'small'),(3 ,'medium'),(3 ,'large');



create table product_Variants( product_Variants_id int  auto_increment primary key,
                            product_id int,
                            productVariantName varchar(50),
                            sku varchar(50),
                            price float
                            );




create table product_details(product_detail_id int auto_increment primary key,
                             product_Variants_id int,

                             value_id int
                             );

insert into product_Variants(product_id,productVariantName,sku,price)
values (1,'red-wool' ,'a121',50);

insert into product_details(product_Variants_id , value_id)
values( 1,1),(1,4);

insert into product_Variants(product_id,productVariantName,sku,price)
values (1,'red-polyester' ,'a122',50);

insert into product_details(product_Variants_id , value_id)
values( 2,1),(2,5);


답변

이 답변에 대한 유사하고 더 나은 해결책을 찾았습니다
/programming/19144200/designing-a-sql-schema-for-a-combination-of-many-to-many-relationship-variation


답변

여러 유형의 제품에 대한 데이터베이스 스키마

해결책은 다음과 같습니다 .http :
//www.codingblocks.net/programming/database-schema-for-multiple-types-of-products/

여기에 이미지 설명을 입력하십시오


답변