2016-11-18       0 个评论    来源: Hello.KK (专注数据库)  
收藏     我要投稿

最近讨论数据库有关产品方案的项目自动扩展问题,即每个方案都有多个项目,而每个方案的项目或多或少,也有不一样的,方案以后也可能随之增加新的项目。因此需要数据库设计一套可扩展的方案。

以商品为例,类似淘宝上的设计,要求如下:

1. 字段自动扩展

2. 属性公用

3. 无限扩展字段

现在,看现实世界的产品:

一个产品怎么在数据库存储呢?如:产品表(产品名称,产品类别,品牌,型号,重量……)

而 产品类别 和 品牌 是冗余的,因此独立出两张表来。

再看看产品,电脑 和手机都有相同或者不同的属性,这只是简单列出,实际有几十或上百个字段,虽然操作方便,但这样设计非常不合理。

产品

类别id

品牌id

型号

内存

颜色

硬盘大小

电池容量

Iphone

1

55

6s

16GB

白色

2750mAh

lenovo

2

333

aaaa

4GB

白色

500 GB

网上有几种方法:

1. 动态添加属性字段。

2. 先预留字段,到时再用。

3. 使用 XML 字段保存。

4. JSON 格式保存。

5. 属性字段行存储

还有一种方法,把相同属性的字段存储到同一个表,不同的属性,每个产品一张表,这可能会有非常多不同产品的特有属性表!

产品表:

产品id

产品

类别id

品牌id

型号

内存

颜色

子表名

1

Iphone

1

55

6s

16GB

白色

表01

67

lenovo

2

333

aaaa

4GB

白色

表02

表01:

产品id

硬盘大小

1

500 GB

表02:

产品id

电池容量

67

2750mAh

所以现在总结考虑的是第五种方法属性字段行存储 。这样就能把所有产品的特有属性都存储到一张表中了!

产品id

属性

1

硬盘大小

500 GB

67

电池容量

2750mAh

现在把所有属性都放到同一个表中,产品和属性分开存储:

产品表:

产品id

产品

类别id

品牌id

1

Iphone

1

55

67

lenovo

2

333

属性表:

产品id

属性

1

型号

6s

1

内存

16GB

1

颜色

白色

1

硬盘大小

500 GB

67

型号

aaaa

67

内存

4GB

67

颜色

白色

67

电池容量

2750mAh

结果如图:

看看 属性表 ,产品相同属性的就出现冗余了,得把属性和值分库两张表:

属性表:

属性id

属性

1

型号

2

内存

3

颜色

4

硬盘大小

5

电池容量

属性值表:

产品id

属性id

1

1

6s

1

2

16GB

1

3

白色

1

4

500 GB

67

1

aaaa

67

2

4GB

67

3

白色

67

5

2750mAh

结构关系如图:

似乎这还不算最终的结果,看 属性值表,对于不同的产品的颜色,也有一样的,属性值表 存储的又会有冗余了,如栗子中的 “白色”。到这里,其实不需要再分表了,有多少属性就插入到该表中。

若是更详细的,继续分表,把值也固定下来。对于颜色,红橙黄绿蓝靛紫等都详细把值都先定义了,在关系表关联对应的颜色就行。当然,属性值表将非常大,因为它包含了所有产品可能的所有参数。所以一般设计到上一步就行了。

属性值:

值id

1

灰色

2

黑色

3

蓝色

4

白色

5

紫色

6

红色

7

白色

(其他)

属性值关系表:

产品id

属性id

值id

1

1

1

2

1

3

4 (白色)

1

4

67

1

67

2

67

3

4(白色)

67

5

==============================================================

==============================================================

最终设计结果如下:

下面给个例子,只是列出关键字段(可自增列)。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use master
go
create database Demo
go
use Demo
go
--类别(父类别)
create table t2_Category(
Categories_id int not null ,
Parent_id int null ,
name varchar (50) not null ,
constraint pk_Category primary key (Categories_id),
)
go
insert into t2_Category
select 1, null , '电器电子' union all
select 2, null , '服装服饰' union all
select 3, null , '办公用品' union all
select 4,1, '电脑' union all
select 5,1, '手机' union all
select 6,2, '帽子' union all
select 7,2, '衣服' union all
select 8,4, '台式电脑' union all
select 9,4, '笔记本' union all
select 10,4, 'Ipad'
go
--品牌
create table t2_Brand(
Brand_id int not null ,
name varchar (50) not null ,
constraint pk_Brand primary key (Brand_id),
)
go
insert into t2_Brand
select 1, '苹果' union all
select 2, '华为' union all
select 3, '小米' union all
select 4, '诺基亚' union all
select 5, '路易·威登' union all
select 6, 'SSPP' union all
select 7, '香奈儿'
go
--产品
create table t2_Procduct(
Procduct_id int not null ,
Categories_id int not null ,
Brand_id int not null ,
name varchar (50) not null ,
constraint pk_Procduct primary key (Procduct_id),
constraint fk_Procduct_Category foreign key (Categories_id) references t2_Category(Categories_id),
constraint fk_Procduct_Brand foreign key (Brand_id) references t2_Brand(Brand_id),
)
go
insert into t2_Procduct
select 1,4,1, 'iMac aaa' union all
select 2,4,1, 'Macbook Air bbb' union all
select 3,4,4, 'Nokia ddd' union all
select 4,5,1, 'Iphone 6' union all
select 5,5,1, 'Iphone 6sp' union all
select 6,5,3, '小米4' union all
select 7,5,3, '红米9' union all
select 8,6,5, '贝雷帽 1999' union all
select 9,7,5, '上衣 COACH 1941' union all
select 10,7,7, '围脖 1945'
go
--属性
create table t2_Property(
Property_id int not null ,
name varchar (50) not null ,
constraint pk_Property primary key (Property_id)
)
go
insert into t2_Property
select 1, '颜色' union all
select 2, '屏幕尺寸' union all
select 3, '屏幕分辨率' union all
select 4, 'CPU型号' union all
select 5, '硬盘容量' union all
select 6, '内存' union all
select 7, '重量' union all
select 8, '手机类型' union all
select 9, '材料' union all
select 10, '衣长'
go
--属性值
create table t2_PropertyValue(
PropertyValue_id int not null ,
Property_id int not null ,
Value varchar (50) not null ,
constraint pk_PropertyValue primary key (PropertyValue_id),
constraint fk_PropertyValue_Property foreign key (Property_id) references t2_Property(Property_id)
)
go
insert into t2_PropertyValue
select 1,1, '白色' union all
select 2,1, '黑色' union all
select 3,1, '红色' union all
select 4,1, '蓝色' union all
select 5,1, '灰色' union all
select 6,2, '360X540' union all
select 7,2, '540X720' union all
select 8,2, '720X960' union all
select 9,2, '720X1280' union all
select 10,6, '1 GB' union all
select 11,6, '2 GB' union all
select 12,6, '4 GB' union all
select 13,6, '8 GB' union all
select 14,7, '100 g' union all
select 15,7, '200 g' union all
select 16,7, '300 g' union all
select 17,7, '400 g' union all
select 18,9, '棉' union all
select 19,9, '亚麻' union all
select 20,9, '人造纤维'
go
--产品属性值表(id,产品,属性,属性值)
create table t2_ProductPropertyValue(
ProductPropertyValue_id int not null ,
Procduct_id int not null ,
Property_id int not null ,
PropertyValue_id int not null ,
constraint pk_ProductPropertyValue primary key (ProductPropertyValue_id),
constraint fk_ProductPropertyValue_Procduct foreign key (Procduct_id) references t2_Procduct(Procduct_id),
constraint fk_ProductPropertyValue_Property foreign key (Property_id) references t2_Property(Property_id),
constraint fk_ProductPropertyValue_PropertyValue foreign key (PropertyValue_id) references t2_PropertyValue(PropertyValue_id)
)
go
insert into t2_ProductPropertyValue
select 1,1,1,1 union all
select 2,3,1,2 union all
select 3,5,1,1 union all
select 4,6,1,4 union all
select 5,7,1,2 union all
select 6,8,1,5 union all
select 7,1,3,6 union all
select 8,1,3,7 union all
select 9,1,3,9 union all
select 10,1,6,11 union all
select 11,1,6,12 union all
select 12,1,7,13 union all
select 13,4,7,14 union all
select 14,5,7,16 union all
select 15,7,7,17 union all
select 16,9,9,18 union all
select 17,9,9,19 union all
select 18,9,9,20 union all
select 19,10,9,19 union all
select 20,10,9,20
go
select * from t2_Category       --类别
select * from t2_Brand          --品牌
select * from t2_Procduct       --产品
select * from t2_Property       --属性
select * from t2_PropertyValue  --属性值
select * from t2_ProductPropertyValue   --产品属性值表

关系图:

?
1
2
3
4
5
6
7
8
9
select t3. name as 类别,t4. name as 品牌,t2. name as 产品,t5. name as 属性,t6.Value as 属性值
from t2_ProductPropertyValue t1
LEFT JOIN t2_Procduct t2 on t1.Procduct_id=t2.Procduct_id
LEFT JOIN t2_Category t3 on t2.Categories_id=t3.Categories_id
LEFT JOIN t2_Brand t4 on t2.Brand_id=t4.Brand_id
LEFT JOIN t2_Property t5 on t1.Property_id=t5.Property_id
LEFT JOIN t2_PropertyValue t6 on t1.PropertyValue_id=t6.PropertyValue_id
order by t3. name ,t4. name ,t2. name ,t5. name ,t6.Value
go

这是当前不同的产品,这里是详细的产品参数。无论怎么搜索产品,都能匹配出来。对于大型网站,所有的类型最好预先定义,让客户选择就行,否则商家随便定义各属性的值的话,记录将非常多(如颜色:赭石色,土黄色,深红色……)。

如果新增一款产品,如 “无人机” ,参数如下:

?
1
2
3
4
5
6
7
8
9
/*
===== 新增产品:无人机 =====
类别:电器电子(已存在)
品牌:大疆
产品:无人机
属性:颜色、重量、轴数  ("颜色"、"重量" 已存在)
属性值:{颜色:白色; 重量:1KG; 轴数:6; }  ("白色" 已存在)
*/

只需要添加没有的记录就行,当然添加前需要判断是否存在。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
--新增
insert into t2_Brand(Brand_id, name ) values (8, '大疆' )
insert into t2_Procduct(Procduct_id,Categories_id,Brand_id, name ) values (11,1,8, '无人机' )
insert into t2_Property(Property_id, name ) values (11, '轴数' )
insert into t2_PropertyValue(PropertyValue_id,Property_id,Value) values (21,7, '1 KG' ),(22,11, '6' )
insert into t2_ProductPropertyValue(ProductPropertyValue_id,Procduct_id,Property_id,PropertyValue_id) values (21,11,1,1),(22,11,7,21),(23,11,11,22)
go
select t3. name as 类别,t4. name as 品牌,t2. name as 产品,t5. name as 属性,t6.Value as 属性值
from t2_ProductPropertyValue t1
LEFT JOIN t2_Procduct t2 on t1.Procduct_id=t2.Procduct_id
LEFT JOIN t2_Category t3 on t2.Categories_id=t3.Categories_id
LEFT JOIN t2_Brand t4 on t2.Brand_id=t4.Brand_id
LEFT JOIN t2_Property t5 on t1.Property_id=t5.Property_id
LEFT JOIN t2_PropertyValue t6 on t1.PropertyValue_id=t6.PropertyValue_id
where t2. name = '无人机'
order by t3. name ,t4. name ,t2. name ,t5. name ,t6.Value
go

基本设计完成。

更多参考:

如何设计动态(不定)字段的产品数据库表?--淘宝多产品属性字段设计方法

中小型商城系统中的分类/产品属性/扩展属性的数据库设计

两难的境界:不定字段数目的数据库表设计和数据结构

关于商品属性设计

点击打开链接

2016-11-18       0 个评论    来源: Hello.KK (专注数据库)  
收藏     我要投稿

最近讨论数据库有关产品方案的项目自动扩展问题,即每个方案都有多个项目,而每个方案的项目或多或少,也有不一样的,方案以后也可能随之增加新的项目。因此需要数据库设计一套可扩展的方案。

以商品为例,类似淘宝上的设计,要求如下:

1. 字段自动扩展

2. 属性公用

3. 无限扩展字段

现在,看现实世界的产品:

一个产品怎么在数据库存储呢?如:产品表(产品名称,产品类别,品牌,型号,重量……)

而 产品类别 和 品牌 是冗余的,因此独立出两张表来。

再看看产品,电脑 和手机都有相同或者不同的属性,这只是简单列出,实际有几十或上百个字段,虽然操作方便,但这样设计非常不合理。

产品

类别id

品牌id

型号

内存

颜色

硬盘大小

电池容量

Iphone

1

55

6s

16GB

白色

2750mAh

lenovo

2

333

aaaa

4GB

白色

500 GB

网上有几种方法:

1. 动态添加属性字段。

2. 先预留字段,到时再用。

3. 使用 XML 字段保存。

4. JSON 格式保存。

5. 属性字段行存储

还有一种方法,把相同属性的字段存储到同一个表,不同的属性,每个产品一张表,这可能会有非常多不同产品的特有属性表!

产品表:

产品id

产品

类别id

品牌id

型号

内存

颜色

子表名

1

Iphone

1

55

6s

16GB

白色

表01

67

lenovo

2

333

aaaa

4GB

白色

表02

表01:

产品id

硬盘大小

1

500 GB

表02:

产品id

电池容量

67

2750mAh

所以现在总结考虑的是第五种方法属性字段行存储 。这样就能把所有产品的特有属性都存储到一张表中了!

产品id

属性

1

硬盘大小

500 GB

67

电池容量

2750mAh

现在把所有属性都放到同一个表中,产品和属性分开存储:

产品表:

产品id

产品

类别id

品牌id

1

Iphone

1

55

67

lenovo

2

333

属性表:

产品id

属性

1

型号

6s

1

内存

16GB

1

颜色

白色

1

硬盘大小

500 GB

67

型号

aaaa

67

内存

4GB

67

颜色

白色

67

电池容量

2750mAh

结果如图:

看看 属性表 ,产品相同属性的就出现冗余了,得把属性和值分库两张表:

属性表:

属性id

属性

1

型号

2

内存

3

颜色

4

硬盘大小

5

电池容量

属性值表:

产品id

属性id

1

1

6s

1

2

16GB

1

3

白色

1

4

500 GB

67

1

aaaa

67

2

4GB

67

3

白色

67

5

2750mAh

结构关系如图:

似乎这还不算最终的结果,看 属性值表,对于不同的产品的颜色,也有一样的,属性值表 存储的又会有冗余了,如栗子中的 “白色”。到这里,其实不需要再分表了,有多少属性就插入到该表中。

若是更详细的,继续分表,把值也固定下来。对于颜色,红橙黄绿蓝靛紫等都详细把值都先定义了,在关系表关联对应的颜色就行。当然,属性值表将非常大,因为它包含了所有产品可能的所有参数。所以一般设计到上一步就行了。

属性值:

值id

1

灰色

2

黑色

3

蓝色

4

白色

5

紫色

6

红色

7

白色

(其他)

属性值关系表:

产品id

属性id

值id

1

1

1

2

1

3

4 (白色)

1

4

67

1

67

2

67

3

4(白色)

67

5

==============================================================

==============================================================

最终设计结果如下:

下面给个例子,只是列出关键字段(可自增列)。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use master
go
create database Demo
go
use Demo
go
--类别(父类别)
create table t2_Category(
Categories_id int not null ,
Parent_id int null ,
name varchar (50) not null ,
constraint pk_Category primary key (Categories_id),
)
go
insert into t2_Category
select 1, null , '电器电子' union all
select 2, null , '服装服饰' union all
select 3, null , '办公用品' union all
select 4,1, '电脑' union all
select 5,1, '手机' union all
select 6,2, '帽子' union all
select 7,2, '衣服' union all
select 8,4, '台式电脑' union all
select 9,4, '笔记本' union all
select 10,4, 'Ipad'
go
--品牌
create table t2_Brand(
Brand_id int not null ,
name varchar (50) not null ,
constraint pk_Brand primary key (Brand_id),
)
go
insert into t2_Brand
select 1, '苹果' union all
select 2, '华为' union all
select 3, '小米' union all
select 4, '诺基亚' union all
select 5, '路易·威登' union all
select 6, 'SSPP' union all
select 7, '香奈儿'
go
--产品
create table t2_Procduct(
Procduct_id int not null ,
Categories_id int not null ,
Brand_id int not null ,
name varchar (50) not null ,
constraint pk_Procduct primary key (Procduct_id),
constraint fk_Procduct_Category foreign key (Categories_id) references t2_Category(Categories_id),
constraint fk_Procduct_Brand foreign key (Brand_id) references t2_Brand(Brand_id),
)
go
insert into t2_Procduct
select 1,4,1, 'iMac aaa' union all
select 2,4,1, 'Macbook Air bbb' union all
select 3,4,4, 'Nokia ddd' union all
select 4,5,1, 'Iphone 6' union all
select 5,5,1, 'Iphone 6sp' union all
select 6,5,3, '小米4' union all
select 7,5,3, '红米9' union all
select 8,6,5, '贝雷帽 1999' union all
select 9,7,5, '上衣 COACH 1941' union all
select 10,7,7, '围脖 1945'
go
--属性
create table t2_Property(
Property_id int not null ,
name varchar (50) not null ,
constraint pk_Property primary key (Property_id)
)
go
insert into t2_Property
select 1, '颜色' union all
select 2, '屏幕尺寸' union all
select 3, '屏幕分辨率' union all
select 4, 'CPU型号' union all
select 5, '硬盘容量' union all
select 6, '内存' union all
select 7, '重量' union all
select 8, '手机类型' union all
select 9, '材料' union all
select 10, '衣长'
go
--属性值
create table t2_PropertyValue(
PropertyValue_id int not null ,
Property_id int not null ,
Value varchar (50) not null ,
constraint pk_PropertyValue primary key (PropertyValue_id),
constraint fk_PropertyValue_Property foreign key (Property_id) references t2_Property(Property_id)
)
go
insert into t2_PropertyValue
select 1,1, '白色' union all
select 2,1, '黑色' union all
select 3,1, '红色' union all
select 4,1, '蓝色' union all
select 5,1, '灰色' union all
select 6,2, '360X540' union all
select 7,2, '540X720' union all
select 8,2, '720X960' union all
select 9,2, '720X1280' union all
select 10,6, '1 GB' union all
select 11,6, '2 GB' union all
select 12,6, '4 GB' union all
select 13,6, '8 GB' union all
select 14,7, '100 g' union all
select 15,7, '200 g' union all
select 16,7, '300 g' union all
select 17,7, '400 g' union all
select 18,9, '棉' union all
select 19,9, '亚麻' union all
select 20,9, '人造纤维'
go
--产品属性值表(id,产品,属性,属性值)
create table t2_ProductPropertyValue(
ProductPropertyValue_id int not null ,
Procduct_id int not null ,
Property_id int not null ,
PropertyValue_id int not null ,
constraint pk_ProductPropertyValue primary key (ProductPropertyValue_id),
constraint fk_ProductPropertyValue_Procduct foreign key (Procduct_id) references t2_Procduct(Procduct_id),
constraint fk_ProductPropertyValue_Property foreign key (Property_id) references t2_Property(Property_id),
constraint fk_ProductPropertyValue_PropertyValue foreign key (PropertyValue_id) references t2_PropertyValue(PropertyValue_id)
)
go
insert into t2_ProductPropertyValue
select 1,1,1,1 union all
select 2,3,1,2 union all
select 3,5,1,1 union all
select 4,6,1,4 union all
select 5,7,1,2 union all
select 6,8,1,5 union all
select 7,1,3,6 union all
select 8,1,3,7 union all
select 9,1,3,9 union all
select 10,1,6,11 union all
select 11,1,6,12 union all
select 12,1,7,13 union all
select 13,4,7,14 union all
select 14,5,7,16 union all
select 15,7,7,17 union all
select 16,9,9,18 union all
select 17,9,9,19 union all
select 18,9,9,20 union all
select 19,10,9,19 union all
select 20,10,9,20
go
select * from t2_Category       --类别
select * from t2_Brand          --品牌
select * from t2_Procduct       --产品
select * from t2_Property       --属性
select * from t2_PropertyValue  --属性值
select * from t2_ProductPropertyValue   --产品属性值表

关系图:

?
1
2
3
4
5
6
7
8
9
select t3. name as 类别,t4. name as 品牌,t2. name as 产品,t5. name as 属性,t6.Value as 属性值
from t2_ProductPropertyValue t1
LEFT JOIN t2_Procduct t2 on t1.Procduct_id=t2.Procduct_id
LEFT JOIN t2_Category t3 on t2.Categories_id=t3.Categories_id
LEFT JOIN t2_Brand t4 on t2.Brand_id=t4.Brand_id
LEFT JOIN t2_Property t5 on t1.Property_id=t5.Property_id
LEFT JOIN t2_PropertyValue t6 on t1.PropertyValue_id=t6.PropertyValue_id
order by t3. name ,t4. name ,t2. name ,t5. name ,t6.Value
go

这是当前不同的产品,这里是详细的产品参数。无论怎么搜索产品,都能匹配出来。对于大型网站,所有的类型最好预先定义,让客户选择就行,否则商家随便定义各属性的值的话,记录将非常多(如颜色:赭石色,土黄色,深红色……)。

如果新增一款产品,如 “无人机” ,参数如下:

?
1
2
3
4
5
6
7
8
9
/*
===== 新增产品:无人机 =====
类别:电器电子(已存在)
品牌:大疆
产品:无人机
属性:颜色、重量、轴数  ("颜色"、"重量" 已存在)
属性值:{颜色:白色; 重量:1KG; 轴数:6; }  ("白色" 已存在)
*/

只需要添加没有的记录就行,当然添加前需要判断是否存在。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
--新增
insert into t2_Brand(Brand_id, name ) values (8, '大疆' )
insert into t2_Procduct(Procduct_id,Categories_id,Brand_id, name ) values (11,1,8, '无人机' )
insert into t2_Property(Property_id, name ) values (11, '轴数' )
insert into t2_PropertyValue(PropertyValue_id,Property_id,Value) values (21,7, '1 KG' ),(22,11, '6' )
insert into t2_ProductPropertyValue(ProductPropertyValue_id,Procduct_id,Property_id,PropertyValue_id) values (21,11,1,1),(22,11,7,21),(23,11,11,22)
go
select t3. name as 类别,t4. name as 品牌,t2. name as 产品,t5. name as 属性,t6.Value as 属性值
from t2_ProductPropertyValue t1
LEFT JOIN t2_Procduct t2 on t1.Procduct_id=t2.Procduct_id
LEFT JOIN t2_Category t3 on t2.Categories_id=t3.Categories_id
LEFT JOIN t2_Brand t4 on t2.Brand_id=t4.Brand_id
LEFT JOIN t2_Property t5 on t1.Property_id=t5.Property_id
LEFT JOIN t2_PropertyValue t6 on t1.PropertyValue_id=t6.PropertyValue_id
where t2. name = '无人机'
order by t3. name ,t4. name ,t2. name ,t5. name ,t6.Value
go

基本设计完成。

更多参考:

如何设计动态(不定)字段的产品数据库表?--淘宝多产品属性字段设计方法

中小型商城系统中的分类/产品属性/扩展属性的数据库设计

两难的境界:不定字段数目的数据库表设计和数据结构

关于商品属性设计

数据库字段动态扩展设计相关推荐

  1. 根据excel列动态创建mysql表_根据数据库字段动态生成excel模版下载,上传模版获取数据存入数据库(poi 反射)...

    环境:mysql5.7.28 java8 Spring boot 2.2.4 mybatis-plus3.10 动态:根据需求,用户可以选择对应的字段生成excle模版 下载 poi 反射:poi是e ...

  2. bootstrap treetable 树形网格,动态扩展,连数据库

    二话不说,先看看效果图: 1.先来看写死的: 展开前~~ 展开后~~ 怎么实现呢? 先new 一个jsp文件,导入几个包,编写html代码,编写js代码,一个文件搞定! 1 <%@ page l ...

  3. Z-Blog 扩展数据库 字段 二次开发

    需求 因为自己写了采集器往Z-Blog数据库中增加数据,友站的文章需要列出出处,尊重版权,所以需要对数据库字段进行扩展,增加采集站点名称和采集详情页链接字段,并且在Z-Blog系统文章页显示出来. 1 ...

  4. 不改表结构如何动态扩展字段

    笔者的动态字段扩展解决方案主要针对 Mysql 5.7.8 以下版本,在 Mysql 5.7.8 已经新增 JSON Data Type,同样适用该方案,而且情况变得更加简单. 痛点 软件行业唯一不变 ...

  5. 设计数据库字段或者java中使用boolean型时需谨慎

    boolean型变量只有两个值 false和true,我们在设计数据库字段时或者定义java变量时会使用boolean,通常情况下开关类的变量使用无可非议,但请一定要考虑到扩展性. 使用前请仔细考虑一 ...

  6. key+value实现动态字段的存储设计

    一般我们在存储例如用户信息的时候,用户信息的各属性是固定的,这时我们可以通过如下方式设计表: user(user_id, name, age, sex) 但是,如果某天呢,产品说用户信息需要加几个属性 ...

  7. 可动态扩展的数据库模型设计

    在通常的数据库设计中,我们定义了每个实体有多少个属性,每个属性的数据类型是什么,有多长,是否允许为空,有什么约束条件等,这些定义是完全静态的,系统创建时就全部定义好,不能动态修改.但是对于实体的属性变 ...

  8. java数据库动态树形菜单_bootstrap treeview树形菜单 动态扩展 连数据库

    二话不说,先来看效果图: 呃呃,虽然不是很美观......不过功能实现就好啦~ 数据库模型是这样的: 我做了什么工作呢? 简单解释一下,就是通过查数据库,把上面的数据查出来,每一行数据封装成为一个节点 ...

  9. Django 数据库查询优化,choices参数(数据库字段设计常见),MVC和MTV模型,多对多三种创建方式...

    数据库查询优化 orm语句的特点:惰性查询 如果仅仅只是书写了orm语句,在后面没有用到该语句所查询出来的参数,那么orm会自动识别,并不执行 举例: res = models.Book.object ...

最新文章

  1. 作为谷歌开发者布道师,我为什么要写这本通俗的《数据压缩入门》(一)
  2. 基于sharepoint 2003的内容管理1.0
  3. phpstudy一直自动停止启动_phpstudy apache启动后停止怎么办?
  4. 构建二叉堆时间复杂度的证明
  5. 罗马数字转整数(C实现)
  6. 数据库图书管理建表与修改表
  7. 22课时、19大主题,CS 231n进阶版课程视频上线!
  8. ES索引管理工具curator安装
  9. android退出一个含有listview的activity时报java.lang.IllegalA
  10. 【更新】PDF控件Spire.PDF 3.9.568发布 | 附下载
  11. C# 使用Microsoft.Reporting打印票据
  12. linux下哪个分区工具好,这些Linux分区工具是免费的且好用
  13. docker 常用命令
  14. 光滑曲线_曲线的曲率
  15. Matlab笔记 第二章 基本操作与矩阵输入
  16. 基于Altium Designer进行单片机逻辑系统及模拟电路原理图设计
  17. C 合成的图片文件的小练习
  18. Unity牧师与魔鬼小游戏(动作分离版)
  19. win10下禁止自动更新,Window Update禁用无效后续方法
  20. 链路聚合(端口聚合)

热门文章

  1. 行内元素和块级元素:内联(行级)元素不能设置margin-top
  2. 计算机保存不了自动还原,win7系统颜色校准无法保存开机自动还原默认的处理步骤...
  3. 如何将PDF文件转换成PPT
  4. 2021年12月中国A股石油加工贸易行业上市企业市值排行榜:中国石油位居榜首,宇新股份股价最高(附月榜TOP24详单)
  5. mysql连接耗尽_避免数据库连接被耗尽的三种配置
  6. oracle数据库所在主机内存耗尽
  7. 脚本及恶意网页攻击实验
  8. 智能车扫线——斑马线识别
  9. 1525D. Armchairs
  10. 计算机网络第七版(谢希仁)第二章——物理层课后习题答案