概念建模场景

Conceptual modelling scenario

我是数据库设计的新手,我一直在练习尽可能多的问题。我碰巧遇到了以下问题(不,这不是我的任务!)根据我的理解,我创建了附加的概念模型。模型中缺少一些信息,因为根据要求,我不清楚应该在哪里添加它们。我已经突出显示了我有疑问的行。

You have been assigned the task to design a database schema that captures the information needed for a facility reviewing service for tourists, for facilities such as accommodations, eateries and planned trips. With regards to the accommodations, the service keeps information about the name, the address, the kind of accommodation. The accommodation type could be hotel, hostel or bed & breakfast. We need also the name and address. There is also an optional set of facilities (which should be listed, separately) such as the kind of rooms (single, double or for more persons), the presence of TV in rooms, bathroom, etc. More than one facility could be applicable to the same place. There is also the cost per night which could be specified either per person (in hostels) or per room (in hotels, bed and breakfasts; therefore, depending on the accommodation type).
For the places to eat we have the name and the address (unique and always available). They could be restaurants, bars, pubs, taverns and self-services. It should be specified the kind of cuisine, the average cost per meal (divided into 4 possible cost levels), the daily time table (composed by the open and close times) and optionally the stop days during the week (one or more days). With regards to the trip, we want to specify the list of the names of the attractions (and corresponding address, if present). For each trip attraction, we have the interval of dates in which the tourists visit them. Each customer can leave a review in free text for each place (accommodation or place to eat but not for tourist trips), specifying his/her nickname (which is unique for all the customers), the date of visit (or alternatively a calendar interval specified by two dates) and a integer score (from 0 to 5). Each customer could visit and leave a review more than once for the same place. Draw the ER diagram for the conceptual design of the database.

这是我想出的: Conceptual Model

图片有我能想到的模型。我的疑惑是:

1) 我的方法使用这么多概括是否正确?还有其他办法吗?

2) 在上面的描述中,第一个斜体和粗体表示存在某些'optional set of facilities'。应该将这些属性添加到酒店、旅馆和 B&B 实体还是广义住宿实体?

3) 在突出显示的第二句话中,是否应该像我所做的那样将费用添加到酒店、旅馆和 B&B 中?否则,我应该如何进行建模?

4) 在第三个突出显示的句子中,指定的属性应该列在每种类型的餐馆下面,还是应该添加到广义实体餐馆?

非常感谢您的提前帮助!

Is my approach correct to use so many generalizations? Is there any other way?

当然还有其他方法。泛化并没有错,尽管在一个模型中很少看到如此多的泛化。这并不意味着它的错误,在这种情况下是对还是错取决于您的模型代表业务需求的程度。

In the description above, the first sentence that is in italics and bold says that there are certain 'optional set of facilities'. Should these attributes be added to Hotel, Hostel and B&B entity or to the generalised Accommodation entity?

这听起来像是一般要求,我会把它与住宿联系起来。

请注意,在给定的场景中 "Facility" 有两种用法 - 可以是 visited/reviewed 的地方,以及房间的特征。我建议重命名其中一个术语以避免混淆。

In the second sentence that is highlighted, should the cost be added to Hotel,Hostel and B&B like I have done? Otherwise, how should I proceed in modelling this?

您可以按照您的方式进行操作,或者向住宿添加成本属性(以及每个 person/room 指标)。

您应该尽量避免在一个属性中混合域。我的意思是所有可能的值都应该是同一类型并且在逻辑上可以互换。一种常见的情况是在一个属性或 EAV 表中的值列中混合不同货币的值。这样的设计往往会增加复杂性。

将成本属性添加到住宿有类似的味道,将每间客房的成本和每人的成本组合在一个属性中。尽管如此,如果它可以消除一组子类型,我会考虑它 - 如果我们没有特定于子类型的属性、关系或约束,类型可以由属性指示,从而减少显式建模每个子类型的需要。

In the third highlighted sentence, should the specified attributes be listed under each type of eatery or should they be added to the generalised entity Eatery?

我认为没有理由为每家餐馆单独列出。所有子类型共有的属性、关系和约束应与超类型相关联。

为了比较,这是我的模型。我在看你的之前就这样做了,所以它采用了一种非常不同的方法。

一些注意事项:

  • 我将房间设施重命名为特色
  • 住宿和餐馆是设施的可选的不相交子类型。这意味着我们可以拥有不属于任何一个子类型的设施,让我可以使用相同的结构处理其他类型的旅游景点的评论。
  • Visit是一个三元关系,由User、Trip和Facility决定。因此,每次访问都必须属于一个旅行,即使它只是一个单次访问的旅行。从好的方面来说,多个用户可以参加同一个旅程。
  • 用户可以在不同的行程中多次访问设施,但每次行程不能超过一次。我们可以使用代理键将 Visit 从关系转换为实体来克服这个问题。

我希望这对您有所帮助,如果我需要澄清任何事情,请告诉我。