简体   繁体   English

星型图:事实与维度之间的三重关系

[英]Star Schema: Triple Relations between Fact and Dimension

I'm modelling a Star Schema from an ERD. 我正在从ERD建模一个Star Schema。 The Database is a rental firm. 该数据库是一家租赁公司。 My fact table now contains a single Rental Booking. 我的事实表现在包含一个出租预订。 Customers are able to book cars, collect cars and return cars. 客户能够预订汽车,收取汽车和回车。 The date of when this happens should be recorded. 发生这种情况的日期应予以记录。

So, my Star Schema now has a Time Dimension with Day/Month/Year and three relations to the fact table. 因此,我的“星型模式”现在具有一个带有日/月/年的时间维度,并且与事实表具有三个关系。 I'm wondering if that's the right way to do or if there are other options to consider, because I have never seen a Star Scheme where a dimension has more than one Relation. 我想知道这是正确的方法还是要考虑其他选择,因为我从未见过一个维度方案具有多个关系的星型方案。

This is it: 就是这个:

 Booking(Fact)
 bookingId
 bookingDate(FK)
 collectionDate(FK)
 returnDate(FK)

 Time(Dim)
 timeId
 day
 month
 year

Yes, you can have a Fact join to the same dimension multiple times. 是的,您可以多次对同一个维度进行事实联接。 I've seen this used with Time dimensions especially. 我已经看到了它特别用于时间维度。 I'm not sure what key you are using to join the Fact to the Time dim, but you may end up with a query like this, when selecting the data: 我不确定使用什么键将Fact关联到Time dim,但是在选择数据时,您可能最终会遇到这样的查询:

select bFact.bookingID,t1.day "Booking Date",t2.day "Collection Date",t3.day "Return Date"
from Booking bFact
join Time t1 on t1.date = bFact.bookingDate
join Time t2 on t2.date = bFact.collectionDate
join Time t3 on t3.date = bFact.returnDate

This is a diagram to try and help you understand better. 这是一个试图帮助您更好地理解的图表。

在此处输入图片说明

If your bookingdate, collectiondate, returndate are all part of the time dimension then you dont need them in the fact table. 如果您的预订日期,收款日期,返回日期都是时间维度的一部分,那么事实表中就不需要它们。 They need to be in the dimension table. 它们必须在尺寸表中。

I have created a diagram that would correctly demonstrate what i think you mean. 我创建了一个图表,可以正确地证明我的意思。 As an example, if return can have different measures then it needs to be a separate dimension. 例如,如果收益可以有不同的度量,则它需要是一个单独的维度。 Each dimension will always need a primary key and these will always correspond to a foreign key in the fact table. 每个维将始终需要一个主键,并且它们将始终与事实表中的外键相对应。

Any questions let me know 有什么问题让我知道

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM