如何在数据库中存储有关企业的可变信息

发布于 2024-11-08 13:35:33 字数 1501 浏览 0 评论 0原文

我正在尝试创建一个类似于 Yelp 的网站(规模较小,市场较小),现在我正处于数据库设计阶段,想知道如何对表进行建模以存储偶尔会发现的“附加业务信息”功能在某些企业列表下,例如:

  • 最近的交通(文本)
  • 接受信用卡(是/否)
  • 有轮椅通道(是/否)
  • 适合儿童(是/否)
  • 停车场(枚举类型 - 街道、车库等)
  • 服装(枚举类型 - 休闲、正式等)
  • 提供(是/否)
  • 等,

请记住,其中一些信息仅适用于特定类别的企业,例如 着装送货信息可能仅适用于餐厅业务 类别,因此将所有内容存储在主 businesses 表中是没有意义的。

我想知道如何存储有关企业的这些额外功能/附加信息,因为它们并不适用于所有企业,也不适用于所有情况。

我正在考虑将每个功能放在它自己的表中,并通过 *biz_id* FK 链接到主要业务表,例如

Businesses
-------------
biz_id (PK)
name
website
isnew
...

Biz_accepts_credit_card
-----------------------
biz_id (FK)
accepts_credit_card (bit field)

Biz_parking (biz can have multiple parking types)
-----------
auto_id (PK)
biz_id (FK)
parking_type {any combination of: street,garage,valet,etc}
...

我的想法是,虽然这会创建大量表只是为了存储这些附加信息,但它也很漂亮灵活,特别是在进一步添加新信息/功能方面,但这可能意味着我必须加入很多表(最坏情况下超过 15 个)才能获取此信息:/

我也想知道是否企业可能属于的不同类别也会对此产生影响。

编辑:阅读@Daveo 的回复后

Features{id, name, ismultiVal} (defines all possible features)

FeatureValues{id, feature_id, value} (defines the possible values each feature can have)

BusinessFeatures{id, biz_id, feature_id, feature_value} (stores the features applicable to each business)

CategoryFeatures_{category_id, feature_id} (what features are found in which categories)

FeatureReviews_{review_id, feature_id, feature_value} (stores the feature values that users voted on in their review of a business)

I'm trying to create a website similar to Yelp (smaller scale, smaller market) and right now i'm in the database design stage and was wondering how to model the tables for storing the 'additional business info' features that are occasionally found under some business listings such as:

  • nearest transit (text)
  • accepts credit card (Y/N)
  • has wheelchair access (Y/N)
  • good for kids (Y/N)
  • parking (enum type - street, garage, etc)
  • attire (enum type - casual, formal, etc)
  • delivers (Y/N)
  • etc

bearing in mind that some of this info only pertains to businesses of a certain category e.g.
the attire and delivers info might only apply to say, businesses in the restaurants
category so it wouldn't make sense to store everything in the main businesses table.

What I'm wondering is how to store these extra features/additional information about a business since they are not applicable to all businesses and not in all cases.

I was thinking of putting each feature in it's own table and linking to the main businesses table through the *biz_id* FK e.g.

Businesses
-------------
biz_id (PK)
name
website
isnew
...

Biz_accepts_credit_card
-----------------------
biz_id (FK)
accepts_credit_card (bit field)

Biz_parking (biz can have multiple parking types)
-----------
auto_id (PK)
biz_id (FK)
parking_type {any combination of: street,garage,valet,etc}
...

My thinking was that while this would create a large amount of tables just for storing this additional info, it would also be pretty flexible, especially in terms of adding new info/features further down the road, but it would probably mean that I would have to be joining lots of tables (15+ in worst case) just for this info :/

I was also wondering if the various categories a business could fall into would have any bearing on this as well.

EDIT: After reading the response from @Daveo

Features{id, name, ismultiVal} (defines all possible features)

FeatureValues{id, feature_id, value} (defines the possible values each feature can have)

BusinessFeatures{id, biz_id, feature_id, feature_value} (stores the features applicable to each business)

CategoryFeatures_{category_id, feature_id} (what features are found in which categories)

FeatureReviews_{review_id, feature_id, feature_value} (stores the feature values that users voted on in their review of a business)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伴我老 2024-11-15 13:35:33

我不会为每个功能制作单独的表格。我会制作一个通用的数据库结构。

 Businesses
    -------------
    biz_id (PK)
    name
    website
    isnew
    ...

    Biz_Feature
    -----------------------
    biz_id (FK)
    feature(FK)

    Feature
    -----------
    Feature_id (PK)
    FeatureType_id (FK)
    name

    Feature_Type
    -----------
    Feature_Type (PK)
    Name

例如,

Feature_Type
1   good for kids
2   parking

Feature
id   type_id    name
1      1         yes
2      1          no
3      2         street
4      2         garage

这就是我要开始的地方。但然后添加额外的信息来确定该功能是否应显示为复选框。

I would NOT make a seperate table for each Feature. I would make a generic database structure.

 Businesses
    -------------
    biz_id (PK)
    name
    website
    isnew
    ...

    Biz_Feature
    -----------------------
    biz_id (FK)
    feature(FK)

    Feature
    -----------
    Feature_id (PK)
    FeatureType_id (FK)
    name

    Feature_Type
    -----------
    Feature_Type (PK)
    Name

E.g.

Feature_Type
1   good for kids
2   parking

Feature
id   type_id    name
1      1         yes
2      1          no
3      2         street
4      2         garage

This is where i would start. But then add extra info to determin if the Feature should display as a checkbox or not.

血之狂魔 2024-11-15 13:35:33

您最终可能需要按功能搜索企业,这意味着这些功能需要建立索引。

Daveo 的建议相当于添加一个 EAV 商店——在我看来,这正是您想要的。您无法有效地为 EAV 存储建立索引。

我正在考虑将每个功能放入其自己的表中,并通过 *biz_id* 链接到主要业务表

如果您最终需要挖掘数据,这确实是正确的方法。

You might end up needing to search businesses by feature, meaning these features will need to be indexed.

What Daveo is suggesting amounts to adding an EAV store -- which is exactly what you do NOT want imo. You cannot index an EAV store efficiently.

I was thinking of putting each feature in it's own table and linking to the main businesses table through the *biz_id*

That is indeed the correct approach if you eventually need to mine the data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文