Task 1 โ Designing the Database 20 marks
Entities, attributes, domains, candidate keys and primary keys (10 marks) plus the detailed ER diagram โ completeness 3, accuracy 3, viva 4.
1(a) โ Entities, attributes, domains & keys
| Entity | Attributes | Domain of each attribute | Candidate key(s) | Primary key |
|---|---|---|---|---|
| DEPARTMENT | dept_id dept_name office_location official_email official_phone | INT (auto) VARCHAR(100) VARCHAR(120) VARCHAR(120) VARCHAR(20) | dept_id dept_name official_email | dept_id |
| DESIGNATION | designation_id designation_title job_category grade_level basic_salary_scale | INT (auto) VARCHAR(80) VARCHAR(50) INT (1โ20) DECIMAL(12,2) โฅ 0 | designation_id designation_title | designation_id |
| EMPLOYEE | employee_id full_name email phone date_of_birth gender national_id present_address permanent_address joining_date employment_type employment_status dept_id (FK) designation_id (FK) | INT (auto) VARCHAR(80) VARCHAR(120) VARCHAR(20) DATE ENUM('Male','Female','Other') VARCHAR(30) VARCHAR(200) VARCHAR(200) DATE ENUM (6 types) ENUM (5 states) INT โ DEPARTMENT INT โ DESIGNATION | employee_id email national_id | employee_id |
| ATTENDANCE | attendance_id employee_id (FK) attendance_date check_in_time check_out_time attendance_status late_status remarks | INT (auto) INT โ EMPLOYEE DATE TIME (null) TIME (null) ENUM (5 states) ENUM('Yes','No') VARCHAR(150) | attendance_id {employee_id, attendance_date} | attendance_id |
| LEAVE_APPLICATION | leave_app_id employee_id (FK) leave_type start_date end_date total_days reason application_date approval_status approved_by (FK) remarks | INT (auto) INT โ EMPLOYEE ENUM (6 types) DATE DATE INT โฅ 1 VARCHAR(200) DATE ENUM (3 states) INT โ EMPLOYEE (null) VARCHAR(150) | leave_app_id | leave_app_id |
| SALARY | salary_id employee_id (FK) basic_salary house_rent_allowance medical_allowance transport_allowance other_allowance total_deduction gross_salary net_salary effective_date salary_status | INT (auto) INT โ EMPLOYEE DECIMAL(12,2) DECIMAL(12,2) DECIMAL(12,2) DECIMAL(12,2) DECIMAL(12,2) DECIMAL(12,2) DECIMAL(12,2) DECIMAL(12,2) DATE ENUM('Active','Inactive') | salary_id {employee_id, effective_date} | salary_id |
How the candidate keys were found. A candidate key is a minimal set of attributes that uniquely identifies a tuple.
dept_nameandofficial_emailare unique per department, so each is a candidate key alongside the surrogatedept_id.- For an employee,
emailandnational_idare naturally unique โ both are candidate keys; the surrogateemployee_idis chosen as PK because it is short, numeric and never changes. {employee_id, attendance_date}is a composite candidate key of ATTENDANCE โ this is exactly the โno two attendance records for the same employee on the same dateโ rule.{employee_id, effective_date}is a composite candidate key of SALARY โ one salary revision per employee per effective date.- LEAVE_APPLICATION has only the surrogate
leave_app_id: an employee may legitimately apply twice on the same date, so no natural combination is guaranteed unique.
1(b) โ Detailed ER diagram
Chen notation: rectangle = entity set, diamond = relationship set, underlined attribute = primary key, 1 / N pills = mapping cardinality, double line = total participation. approves is a second relationship between EMPLOYEE and LEAVE_APPLICATION with the roles approver and applicant.
Reading the diagram
| Relationship | Between | Cardinality | Participation |
|---|---|---|---|
| works in | DEPARTMENT โ EMPLOYEE | 1 : N | Total on EMPLOYEE (every employee must have a department) |
| holds | DESIGNATION โ EMPLOYEE | 1 : N | Total on EMPLOYEE (exactly one current designation) |
| has | EMPLOYEE โ ATTENDANCE | 1 : N | Total on ATTENDANCE |
| applies for | EMPLOYEE โ LEAVE_APPLICATION | 1 : N | Total on LEAVE_APPLICATION |
| approves | EMPLOYEE โ LEAVE_APPLICATION | 1 : N | Partial โ a Pending application has no approver yet |
| draws | EMPLOYEE โ SALARY | 1 : N | Total on SALARY (history of revisions) |
Two points the examiner will probe. (1) Why is there no weak entity here? ATTENDANCE and SALARY look weak (they depend on an employee), but each was given its own surrogate key, so they are strong entities with a total-participation FK. If you instead identified them by
{employee_id, attendance_date}, they would be weak entity sets with a double rectangle, a double diamond and a dashed-underlined discriminator โ say this out loud, it is worth marks. (2) Why two relationships to LEAVE_APPLICATION? Because employee_id and approved_by are different roles of the same entity set. Notation refresher: Lecture 3 โ ER Diagram & EER โ