Weeks 1–2 · Original 100-mark exam, followed by focused 35-mark paper
Note: Answers are generated by AI, answers may be inaccurate or incomplete
A1. Database — An organised collection of related data, e.g. students, modules and enrolments at a university.
A2. DBMS — Software for creating, managing and accessing databases. Benefits include controlled concurrent access, less redundancy, constraints and improved integrity.
A3. Schema versus data — A schema describes tables, columns, types, constraints and relationships; data are the actual stored records.
A4. ER components — Entity: Student. Attribute: StudentID. Relationship: Student enrols in Module.
A5. PK versus FK — A primary key uniquely identifies a row and cannot be NULL. A foreign key references a key in another table; for example Enrolment.StudentID refers to Student.StudentID.
A6. Relationship cardinalities — 1:1 Person–Passport; 1:M Lecturer–Module; M:M Student–Module. Participation may be optional depending on the requirements.
A7. Junction table — An Enrolment(StudentID, ModuleID) junction table represents a many-to-many link as two one-to-many links, without repeating module columns or storing lists in a cell.
A8. Normalisation — Organising tables to reduce unnecessary duplicate data, maintain consistency and avoid insert, update and delete anomalies.
A9. 1NF — The slides require atomic values, a primary key and no duplicated rows or columns / repeating groups.
A10. 2NF — Satisfies 1NF and no non-key attribute depends on only part of a composite candidate key. E.g. StudentName depends on StudentID, not the whole (StudentID,ModuleID) pair.
A11. 3NF — A transitive dependency is a non-key attribute determining another non-key attribute, e.g. StudentID → Postcode → City; splitting related facts prevents redundancy and update anomalies.
A12. Database anomalies — INSERT: cannot store a fact without unrelated data. UPDATE: duplicated facts become inconsistent. DELETE: removing one fact accidentally removes another.
A13. CRUD — Create=INSERT; Read=SELECT; Update=UPDATE; Delete=DELETE.
A14. SQL and psql — SQL statements commonly end with a semicolon, e.g. SELECT ...; psql special commands start with backslash, e.g. \c database_name.
Each answer is worth 2 marks.
| Question | Answer | Explanation |
|---|---|---|
| B1 | B | A schema describes database design and constraints. |
| B2 | C | DBMSs offer structured controlled multi-user access. |
| B3 | B | StudentID is an attribute. |
| B4 | C | Lecturer to Module is one-to-many. |
| B5 | B | Foreign key normally resides on the many side. |
| B6 | B | A junction table represents M:M in relational tables. |
| B7 | A | A cell with multiple values violates 1NF. |
| B8 | B | 2NF removes partial dependencies. |
| B9 | A | A transitive dependency goes through another non-key attribute. |
| B10 | C | Accidental loss of a class record is a DELETE anomaly. |
| B11 | B | A PK identifies rows uniquely and cannot be NULL. |
| B12 | C | SELECT retrieves records. |
| B13 | C | DELETE without WHERE removes every row, not the table definition. |
| B14 | D | \c is a psql meta-command. |
| B15 | B | ManyToMany relates potentially many entities on both sides. |
Blanks in order: TABLE, NOT, NULL, TEXT, student_id.
CREATE TABLE Student (
student_id INTEGER NOT NULL,
name TEXT,
PRIMARY KEY (student_id)
);CREATE TABLE is SQL, unlike JDL entity. A primary key is unique and non-null.
Blanks in order: String, String, ManyToMany, modules, students.
entity Student {
name String required
}
entity Module {
title String required
}
relationship ManyToMany {
Student{modules} to Module{students}
}Lowercase field/navigation names, and JDL String rather than SQL TEXT. Equivalent meaningful navigation names can work in free-response JDL.
The statement DELETE FROM student; has no WHERE and deletes all student rows.
DELETE FROM student WHERE student_id = 7;
The statement removes only the row with student_id 7, assuming the table uses that column name.
The result is one row with title = Web Programming.
SELECT title FROM Module WHERE module_id = 2;
SELECT specifies the returned column, FROM selects the table, and WHERE chooses matching rows.
Correct entities and two relationships; a bidirectional OneToMany models Lecturer–Module. Equivalent ManyToOne with correct direction may also express the same cardinality.
entity Student {
name String required
email String required unique
}
entity Module {
title String required
credits Integer required
}
entity Lecturer {
fullName String required
}
relationship ManyToMany {
Student{modules} to Module{students}
}
relationship OneToMany {
Lecturer{modules} to Module{lecturer}
}JHipster typically creates Student, Module and Lecturer tables; a Student–Module join table holding their foreign keys; and a lecturer foreign key on the Module (many) side. Generated names may vary.
15 multiple choice (15 marks) followed by 5 written/code (20 marks).
| Question | Answer | Explanation |
|---|---|---|
| 1 | C | The combination (StudentID, ModuleID), not either field individually, identifies the row. |
| 2 | B | Rows with an equal StudentID must have the same StudentName. |
| 3 | D | StudentName depends on only one part of the composite key. |
| 4 | A | StudentID determines Postcode, which in turn determines City. |
| 5 | C | Move the student name to a Student table and retain enrolment pairs. |
| 6 | B | A single-column primary key cannot have a dependency on only part of a composite primary key. |
| 7 | D | Module is the many side and holds lecturer_id. |
| 8 | A | A junction table connects students and modules without repeating groups. |
| 9 | C | DepartmentID determining DepartmentName introduces a transitive dependency. |
| 10 | B | DELETE without WHERE removes all rows, not the table definition. |
| 11 | D | UPDATE ... SET ... WHERE ... is the correct command order. |
| 12 | A | \c is a psql command. |
| 13 | C | JDL syntax is email String required unique. |
| 14 | B | Both lecturer.getModules() and module.getLecturer() are available. |
| 15 | D | JHipster normally generates a junction table. |
Definition (1): A → B means that whenever two rows agree on A, they must also agree on B; A determines B.
Example (1): StudentID → StudentName: a given StudentID identifies one stored StudentName.
Reverse direction (2): StudentName → StudentID need not hold because different students may share the same name. Note that a functional dependency does not mean different IDs must have different names.
Dependency one (1): StudentID → StudentName.
Dependency two (1): ModuleID → ModuleTitle.
Why 2NF is violated (1): Each non-key attribute depends on only one part of composite PK (StudentID, ModuleID).
Correct decomposition (2): Student(StudentID PK, StudentName); Module(ModuleID PK, ModuleTitle); Enrolment(StudentID FK, ModuleID FK, composite PK(StudentID, ModuleID)).
First dependency (1): StudentID → Postcode.
Second dependency (1): Postcode → City (as assumed by the question).
Identify issue (1): StudentID → City indirectly through Postcode, a non-key attribute: transitive dependency.
Decomposition (2): Student(StudentID PK, Postcode FK); PostcodeCity(Postcode PK, City). This assumes each postcode determines exactly one city.
Risk (1):
DELETE FROM Student; has no WHERE clause and removes every student row.
Correct SQL (2):
DELETE FROM Student WHERE student_id = 7;
JDL entities and relationship (2):
entity Student {
name String required
}
entity Module {
title String required
}
relationship ManyToMany {
Student{modules} to Module{students}
}
Generated table (1): A student–module junction table holding references to Student and Module, often with a composite key or unique pair.