2010-08-16 65 views
0

我需要爲需要存儲不同列的2種農民(組織和業主)創建數據庫,我還需要爲他們的信息進行版本化。consotypent vs性能數據庫設計db版本多態性

,我想出了一個DB設計是這樣的:(一致的)

Farmers 
Id 
FType check(FType in ('organization', 'landlord')) 
Unique(Id,Ftype)  

Organizations 
Id 
FType 
Unique(Id, FType) 
FK(Id, FType) Ref Farmers(Id, FType) 

LandLords 
Id 
FType 
Unique(Id, FType) 
FK(Id, FType) Ref Farmers(Id, FType) 

OrganisationVersions 
Id 
OrganisationId ref Organizations(id) 
--lots of stuff specific to organisation 
Startdate 
Endate -- if null than this is the current version 

LandLordVersions 
Id 
LandLordId ref LandLords(id) 
--lots of stuff specific to landlord 
StartDate 
EndDate 

第二個不那麼一致,但要少得多的表是這樣的:

Farmers 
Id 
FType 

Organizations 
Id 
FarmerId ref Farmers(Id) 
--stuff 
StartDate 
EndDate -- if null than this is the current version 

LandLords 
Id 
FarmerId ref Farmers(Id) 
--stuff 
StartDate 
EndDate 
+0

你會在舊版本上工作的頻率如何?這些只是歷史守護者,或者你有一些邏輯,這需要不同的舊版本? – 2010-08-16 08:55:01

+0

@Nitin Midha是歷史飼養員,但我也需要加入他們有時候,其他一些表將直接引用版本表 – Omu 2010-08-16 09:02:33

回答

1

我不在第二個版本中看不到任何特別的困難。第一個版本在Organizations表和Landlords表中有一個FType列,這似乎不是必須的,因爲它對於所有行都是相同的。

在同一個表中有多個版本的每個條目,當前版本的最新結束日期爲NULL也似乎很好;您可以創建一個只顯示當前行的視圖'Current_Landlords';這樣的觀點可以更新。有些索引可能需要幫助。

+0

Ftype是必要的,因爲它是農民的FK,所以這種方式只有組織將能夠引用「組織」類型的農民,只有業主能夠引用'地主'類型的農民 – Omu 2010-08-16 09:04:29

+0

您不需要FType作爲Farmers表中的主鍵的一部分;你只需要這個id是唯一的。否則,您可能會以組織1號和地主號碼1結束,這隻會造成不必要的混淆。 – 2010-08-16 09:23:24

+0

這不可能發生,因爲組織和地主表中的(id,Ftype)是FK到Farmers表,其中Id是PK – Omu 2010-08-16 09:36:01