The database for "Sunnyvale", a fictitious gated community, is designed to keep a record of all data possibly relevant to a gated community.
The following are the entities that exist within the scope of this database:
- People - All human entities, and their basic identifying information
- Houses - Houses within the gated community, and their basic identifying information
- Vehicles - All vehicles associated with the gated community, and their basic identifying information
- Residents - A subset of the "people" table representing the residents of the gated community,
connecting them to their respective houses, vehicles, and whether they are homeowners, tenants, or past residents - Visitors - A subset of the "people" table representing the visitors of the gated community,
connecting them to their vehicles, which houses they have come to visit and the purpose of their visit - Staff - A subset of the "people" table representing the staff of the gated community,
connecting them to their vehicles, which houses they are employed at, the nature of their work,
and whether they stay with their employers, or whether they visit their employers on a daily basis - Gate logs - A log of entry and exit timestamps of all people who enter/exit the gated community
Non-core attributes like pets, property sizes, make and model of vehicles, other unimportant identifying information of residents like their age, date of birth,
their position in the community's housing association, etc. are out of the scope of this database.
This database can be utilized to:
- Keep a track of what houses are occupied, and what houses are available for sale/lease
- Keep a track of the comings and goings of people in the community through the gate logs
- Add/update details of residents, visitors, staff members, vehicles, houses
- Look up staff members who perform certain roles, like a cook, if a resident requires a cook
- Keep a track of which vehicles belong to which resident, or which houses they are parked in
- Find houses of a particular configuration for sale/lease
At this stage, the database does not support deleting entities, which does make sense from a record-keeping perspective
as it would be ideal to have a record of all the entities that have interacted with this gated community.
The database includes the following entities:
The people
table includes:
id
- specifies the unique ID for the person as anINTEGER
. This column has thePRIMARY KEY
constraint applied.first_name
- specifies the person's first name asTEXT
, sinceTEXT
is appropriate for name fields.last_name
- specifies the person's last name asTEXT
, sinceTEXT
is appropriate for name fields.contact_number
- specifies the person's contact number asTEXT
, so that symbols, or leading/trailing "0" digits are not lost.email
- specifies the person's email asTEXT
, asTEXT
is appropriate to capture email addresses which will most likely have a mix of symbols, alphabets, digits in them.
All columns in the people
table are required. Therefore, each column has the NOT NULL
constraint applied to it,
unless the column already has a PRIMARY KEY
or FOREIGN KEY
constraint applied to it.
The houses
table includes:
id
- specifies the unique ID for the house as anINTEGER
. This column has thePRIMARY KEY
constraint applied.house_number
- specifies the house's number asTEXT
. This is because the house number may have symbols, or alphabets in it.
This column has theUNIQUE
constraint applied to ensure no two houses have the samehouse_number
.house_name
- specifies the house's name asTEXT
, sinceTEXT
is appropriate for name fields. This column can be blank/NULL
.configuration
- specifies the house's configuration asTEXT
, since the value for this is a mix of digits and alphabets. This column has
aCHECK
constraint applied to ensure theconfiguration
value falls within an approved category of'2BHK', '3BHK', or '4BHK'
.occupancy_status
- specifies the house's availability asTEXT
. This column has aCHECK
constraint applied to ensure theoccupancy_status
value
falls within an approved category of'Available', or 'Occupied'
.
All columns in the houses
table (except for house_name
) are required. Therefore, each column has the NOT NULL
constraint applied to it,
unless the column already has a PRIMARY KEY
or FOREIGN KEY
constraint applied to it.
The vehicles
table includes:
id
- specifies the unique ID for the vehicle as anINTEGER
. This column has thePRIMARY KEY
constraint applied.number_plate
- specifies the number plate for the vehicle asTEXT
.
This column has theDEFAULT
constraint applied if a person does not own a vehicle, to set the value to'N/A'
.people_id
- specifies the unique ID of the person who owns the vehicle as anINTEGER
.
This column has theFOREIGN KEY
constraint applied, referencing theid
column in thepeople
table to ensure data integrity.house_id
- specifies the unique ID of the house where the vehicle is parked as anINTEGER
.
This column has theFOREIGN KEY
constraint applied, referencing theid
column in thehouses
table to ensure data integrity.
The residents
table includes:
id
- specifies the unique ID for the relationship of a resident with their house and their vehicle as anINTEGER
. This column has thePRIMARY KEY
constraint applied.people_id
- specifies the unique ID of the resident as anINTEGER
.
This column has theFOREIGN KEY
constraint applied, referencing theid
column in thepeople
table to ensure data integrity.house_id
- specifies the unique ID of the resident's house as anINTEGER
.
This column has theFOREIGN KEY
constraint applied, referencing theid
column in thehouses
table to ensure data integrity.vehicle_id
- specifies the unique ID of the resident's vehicle as anINTEGER
.
This column has theFOREIGN KEY
constraint applied, referencing theid
column in thevehicles
table to ensure data integrity.resident_status
- specifies if the resident is a homeowner, a tenant, or a past resident asTEXT
. This column has aCHECK
constraint applied
to ensure theresident_status
value falls within an approved category of'Owner', 'Tenant', or 'Ex-Resident'
.
All columns in the residents
table are required. Therefore, each column has the NOT NULL
constraint applied to it,
unless the column already has a PRIMARY KEY
or FOREIGN KEY
constraint applied to it.
The visitors
table includes:
id
- specifies the unique ID for the relationship of a visitor with the house they're visiting and their vehicle as anINTEGER
.
This column has thePRIMARY KEY
constraint applied.people_id
- specifies the unique ID of the visitor as anINTEGER
.
This column has theFOREIGN KEY
constraint applied, referencing theid
column in thepeople
table to ensure data integrity.house_id
- specifies the unique ID of the house the visitor is here to visit as anINTEGER
.
This column has theFOREIGN KEY
constraint applied, referencing theid
column in thehouses
table to ensure data integrity.vehicle_id
- specifies the unique ID of the visitor's vehicle as anINTEGER
.
This column has theFOREIGN KEY
constraint applied, referencing theid
column in thevehicles
table to ensure data integrity.purpose_of_visit
- specifies the reason why the visitor is at the gated community asTEXT
.
All columns in the visitors
table are required. Therefore, each column has the NOT NULL
constraint applied to it,
unless the column already has a PRIMARY KEY
or FOREIGN KEY
constraint applied to it.
The staff
table includes:
id
- specifies the unique ID for the relationship of a staff member with the house they're employed at and their vehicle as anINTEGER
.
This column has thePRIMARY KEY
constraint applied.people_id
- specifies the unique ID of the staff member as anINTEGER
.
This column has theFOREIGN KEY
constraint applied, referencing theid
column in thepeople
table to ensure data integrity.house_id
- specifies the unique ID of the house the staff member works at as anINTEGER
.
This column has theFOREIGN KEY
constraint applied, referencing theid
column in thehouses
table to ensure data integrity.vehicle_id
- specifies the unique ID of the staff member's vehicle as anINTEGER
.
This column has theFOREIGN KEY
constraint applied, referencing theid
column in thevehicles
table to ensure data integrity.employment_role
- specifies the staff member's nature of employment asTEXT
.employment_type
- specifies the type of employment the staff member has taken on asTEXT
. This column has aCHECK
constraint applied
to ensure theemployment_type
value falls within an approved category of'Daily Visits', or 'Staying'
.
All columns in the staff
table are required. Therefore, each column has the NOT NULL
constraint applied to it,
unless the column already has a PRIMARY KEY
or FOREIGN KEY
constraint applied to it.
The gate_logs
table includes:
id
- specifies the unique ID for the gate log as anINTEGER
. This column has thePRIMARY KEY
constraint applied.people_id
- specifies the unique ID of the person as anINTEGER
.
This column has theFOREIGN KEY
constraint applied, referencing theid
column in thepeople
table to ensure data integrity.entry
- specifies the entry timestamp of the person asNUMERIC
. This column has aDEFAULT
constraint applied,
where if there is no value entered into this column, the current timestamp will be automatically entered instead.exit
- specifies the exit timestamp of the person asNUMERIC
. This column has aDEFAULT
constraint applied,
where if there is no value entered into this column, the current timestamp will be automatically entered instead.
All columns in the gate_logs
table are required. Therefore, each column has the NOT NULL
constraint applied to it,
unless the column already has a PRIMARY KEY
or FOREIGN KEY
constraint applied to it.
The below entity relationship diagram describes the relationships among the entities in the database.
As seen in the above entity relationship diagram:
- There is a 1-to-1 relationship between the concept of a person, and their classification as a resident, a visitor or a staff member.
- A person, no matter their classification, can own zero or many vehicles. However, if a vehicle exists, it must have atleast one owner.
- A vehicle can be associated with one or many houses. A house can have zero or many vehicles associated with it.
- A person, no matter their classification, can have zero or many gate logs. However, if a gate log row exists, it is associated with one person only.
- A resident can own/lease one or many houses, and a house can have zero or many residents.
- A visitor can visit one or many houses, and a house can have zero or many visitors.
- A staff member can be employed at one or may houses, and a house can have zero or many staff members.
For optimizing the database to handle common queries, the following indexes were created:
- The
house_configuration_search
index was created on theconfiguration
andoccupancy_status
columns of thehouses
table to allow for a faster look-up of what houses are available for sale/lease, and what the configuration of these available houses are. - The
staff_role_search
index was created on thepeople_id
andemployment_role
columns of thestaff
table to allow for a faster look-up of what staff members offer what services in the community, in a situation where a resident of the community is looking to employ a staff member with a certain skillset, like a cook, for example.
The database also includes the following views:
owners
- Easy access to all information (except IDs) relating to homeowners in the gated community.tenants
- Easy access to all information (except IDs) relating to tenants in the gated community.visitor_info
- Easy access to all information (except IDs) relating to visitors of the gated community.staff_info
- Easy access to all information (except IDs) relating to staff members of the gated community.
The current design of this database lacks a proper method to represent security guards, since the staff
table ties a staff member to a house, but security guards are more often than not for the entire gated community. It also lacks the ability to delete records easily, since all the tables are so heavily linked with foreign keys, though this might be a net positive because when it comes to record-keeping, it would be ideal to have all the records for reference. It also does not have a structure for a housing association, which is found in almost every community anywhere.