views:

45

answers:

1

I need to create a database for 2 types of farmers (organizations and landlords) which have different columns that need to be stored and I also need to version their info.

One db design that I came up with is this: (the consistent one)

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

The second one not so consistent but much less tables is like this:

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
+1  A: 

I don't see any especial difficulties with your second version. The first version has an FType column in the Organisations table and the Landlords table, which doesn't seem to be necessary as it will be the same for all rows.

Having multiple versions of each entry in the same table, with the latest end date as NULL for the current version also seems fine; you could create a view 'Current_Landlords' where only the current row is displayed; such a view would be updatable. Some indexes might be necessary to help it out.

Brian Hooper
the Ftype is necessary because it is an FK to Farmers so this way only organizations will be able to reference Farmers of type 'organization' and only landlords will be able to reference Farmers of type 'landlord'
Omu
You don't need FType as part of the primary key in the Farmers table; you just need the id to be unique. Otherwise you might end up with Organisations number 1 and Landlords number 1, which will just cause unnecessary confusion.
Brian Hooper
this can't happen because the (id,Ftype) from organizations and landlords tables are FK to Farmers table where Id is PK
Omu