我制作存储广告的数据表。
我的广告表如下所示:
Advertisement:
id (PK)
title
description
category_id (FK)
..
我有2种不同类型的广告:我存储汽车和房地产。
因此,我具有两种类型都不同的属性。即汽车具有品牌和门数,而房地产具有房间数。
因此,我想问一下存储这种关系的最佳方法是什么。
我应该将所有值都放在一个大的广告表中,但是有些值始终为空是不利的。
还是我应该再制作2个表,并在广告表中保留公用值?
CarTable
id(PK)
advertisement_id (FK)
brand
numberOfDoors
...
RealEstateTable
id(PK)
advertisement_id (FK)
nrOfRooms
...
我认为带有两个额外表的第二个解决方案不是很好。
有什么建议么?谢谢
最佳答案
方式之一可能是:
Advertisement:
id (PK)
title
description
category_id (FK)
..
Attribute type:
id (PK)
name
code (can be optional)
Advertisement's attributes:
id (PK)
Advertisement id (FK)
Attribute id (FK)
Attribute value