2015-07-21 64 views
1

我是數據倉庫的新手,所以請容易在我身上。找出我的數據倉庫中的維度表的數量

我想弄清楚在這種情況下的維數。

在我的交易數據庫:

  • 我有一個表,該表存儲位置代碼。列是location_code int not null primary key, short_description varchar(10) not null, long_description varchar(100) not null

  • 我有一個存儲區域代碼的表。列是region_code int not null primary key, short_description varchar(10) not null, long_description varchar(100) not null

  • 我有一個關聯位置和區域的表格。列是assoc_id int not null primary key, location_code int not null, region_code int not null。 1位置僅屬於1個地區。

在我的數據倉庫數據庫用戶可能希望按位置或按地區查找數據。

現在我期待在這種情況下,以創建維度表(一個或多個)。

想知道我應該創建2個維表(1位置和1區)這樣?

  • 創建1代維度表的位置也有地區與這些列:region_code int not null primary key, region_short_description varchar(10) not null, region_long_description varchar(100) not null, location_code int not null, location_short_description varchar(10) not null, location_long_description varchar(100) not null

OR:location_code int not null primary key, location_short_description varchar(10) not null, location_long_description varchar(100) not null, region_code int not null, region_short_description varchar(10) not null, region_long_description varchar(100) not null

  • 的區域,該區域也具有與這些列位置創建1個維度表我要創建(對於地點區關聯,1區域的定位協會1位置,1區,1)這樣4個維度表?

    • 與這些列創建位置1個維度表:location_code int not null primary key, short_description varchar(10) not null, long_description varchar(100) not null

    • 與這些列創建1代維度表的地區:region_code int not null primary key, short_description varchar(10) not null, long_description varchar(100) not null

    • 與這些列的位置區關聯創建1個維度表:location_code int not null, region_code int not null

    • 創建1代維度表與這些列區域的定位協會:region_code int not null, location_code int not null

    還是有另一種方式,也更有意義?如果是,請一定要告訴

    在數據倉庫的世界裏,什麼樣的關係是這樣叫,什麼是處理它的標準方式?

    感謝

  • +0

    這是哪個流程的業務視圖?要獲得有意義的答案,您應該解釋「數據」是什麼以及位置和區域是什麼。例如銷售是「數據」嗎?位置是屬於某個位置的地理位置嗎?地點可能重疊嗎? – momobo

    +0

    @momobo數據是所有員工在特定位置工作的小時數。因此,例如位置L1的1500小時和位置L2的2400小時。位置是地理位置,位置不能重疊。一個地區有一個或多個地點。 1位置只能屬於1個地區。 – ChumboChappati

    回答

    0

    我會模式在同一維度的位置UND地區(根據業務使用命名,例如D_Location,或D_Geography)。

    小時數將在事實數據表和事實數據表中F_Hour和D_Location將與代理鍵(Oracle中的序列或Sql服務器中的標識)連接。

    區域和位置的所有描述性列可以愉快地生活在D_Location中(當然區域不會被標準化,但通常是這樣做的)。

    +0

    對於特定區域,您如何計算小時數? – ChumboChappati

    +0

    從F_Hour加入D_Location的F_Hour.keyLocation = D_Location.keyLocation其中D_Location.Region =「Region 01」 – momobo

    0

    我想你不需要跟蹤維度表中的位置和區域的關聯。該關聯可以在事實表中。

    我將創建2個維表D_Location & D_Region和1個事實表F_Hour

    D_Location:

    location_code int not null primary key, short_description varchar(10) not null, long_description varchar(100) not null 
    

    D_Region:

    region_code int not null primary key, short_description varchar(10) not null, long_description varchar(100) not null 
    

    F_Hour:

    hour_id int not null primary key, location_code int not null, region_code int not null, hours decimal(10,2) not null 
    

    F_Hour將有1 FK到D_Location和1 FK到D_Region

    要獲取小時特定location_code(@location_code):

    select h.location_code, l.short_description, l.long_description, sum(h.hours) 
    from F_Hour h inner join D_Location l on h.location_code = l.location_code 
    where h.location_code = @location_code 
    group by h.location_code, l.short_description, l.long_description 
    order by h.location_code 
    

    要獲取小時特定REGION_CODE(@region_code):

    select h.region_code, r.short_description, r.long_description, sum(h.hours) 
    from F_Hour h inner join D_Region r on h.region_code = r.region_code 
    where h.region_code = @region_code 
    group by h.region_code, r.short_description, r.long_description 
    order by h.region_code 
    

    是否有意義?

    +0

    這個看起來與事務數據庫非常相似的總和(小時)可以考慮使用數據倉庫解決方案嗎?我不確定@momobo您對這個解決方案有什麼看法? – ChumboChappati

    +0

    我認爲它有效。只有,我只會使用一個維度,而我會使用代理鍵。 – momobo