Forum Moderators: open
can anyone tell me what fields should i use, because there are 3 types of properties villa's,buildings and ware houses. and i can't put number_of_apartments in a villa, so how should i do the structure of the database
Thank you :)
Another, probably technically better, option would be to have a properties table and then separate tables for things like apartment info. So:
property:
id type ...
1 villa ...
2 building ...
apartment_info:
id_property number_of_apartments other_useful_apartment_info_field ...
2 6 ...
Then in the code if the type of a property is a building you'd look in the apartments table but not if it was a villa. Or use a join. Actually, even this structure isn't optimal - you'll be repeating the words villa, building, etc in properties - so there should be a table for those (which, incidentally, could also store the required fields for this property type).
If this seems a bit vauge/run on sorry about that - de-obfustication is left as an excercise to the student ;)
Usually the best way to approach these sorts of problems is to write all of the possible fields down and then get those fields into a normalized database structure:
[databasejournal.com...]
What about something like that?
TABLE: tProperty (this table should contain attributes that are common to ALL property types)
PropertyID
PropertyType
PropertyAddress (or AddressID if you keep all address types in a separate address table)
ListedPrice
ListingDate
ListingExpirationDate
CommissionType (Fixed, Percentage)
CommissionAmount (if CommissionType = fixed - Not sure if peeps every get paid flat fee for selling)
CommisionPercentage (if CommissionType = Percentage - This is normally how real estate agents/brokers are paid)
YearBuilt
HeatedSquareFeet
Acreage (I would put this here even though for a mobile home it may not always apply - only if selling lot+mobilehome)
...
Think of the above table as a superclass (like shapes) if you're familiar w/ Object Oriented programming. This would contain all attributes of properties that apply to ALL property types.
Then I would have a separate table for each sub-class (like circle, square, rectangle, tetrahedron, etc) of property such as single family detached houses, condominiums, duplexes, apartments, mobile homes, warehouses, etc. similar to the following:
TABLE: tSingleFamilyDetached
PropertyID (Foreign Key back to tProperty.PropertyID)
BedroomCount
BathroomCount
GarageType (none, 1car, 2car, etc)
Fireplaces (0,1,2,3, etc)
...
TABLE: tCondominium
PropertyID (Foreign Key back to tProperty.PropertyID)
BedroomCount
BathroomCount
GarageType (none, 1car, 2car, etc)
Fireplaces (0,1,2,3, etc)
HomeOwnersAssociationDues
TABLE: tMobileHomes
PropertyID (Foreign Key back to tProperty.PropertyID)
BedroomCount
BathroomCount
Manufacturer
Model
MobileHomeType (single-wide, double-wide)
Width (12', 14', 24', 28', etc)
Length (50', 60', 70')
Weight
....
and so on for all PropertyTypes.
If you're looking for high level info about a property, frequently you can get it from just the tProperty table. But if you need details for a particular type you join tProperty with one or more Property sub-class tables.
For example, if PropertyType=1 is an apartment building and you want all of the info about apartment buildings listed so far the month of November, you might do something like:
SELECT *
FROM tProperty p
JOIN tApartment a ON p.PropertyID = a.PropertyID
WHERE p.PropertyType = 1 AND p.ListingDate > '11/01/2008'
Hope this helps...
Zydo
[edited by: ZydoSEO at 9:11 pm (utc) on Nov. 7, 2008]