UNIHIVE

Study Hub UNIPORT CSC 282

CSC 282 · Database Programming

Designing a database: ER diagrams and normalisation

Entities, attributes and relationships, turning an ER diagram into tables, and first, second and third normal form.

Our notes

2 min read

Entity-relationship (ER) modelling

  • Entity: a thing we keep data about (Student, Course, Lecturer).
  • Attribute: a property (Surname, Units).
  • Relationship: how entities are linked (Student registers for Course), with cardinality (1:1, 1:N, M:N) and participation (must every student register for a course? then participation is total).

In Chen notation entities are rectangles, attributes ovals, relationships diamonds; crow's-foot notation draws the "many" end as a three-pronged foot.

From ER diagram to tables

  1. Each entity → a table, its identifier → primary key.
  2. 1:N relationship → foreign key on the many side.
  3. M:N relationship → a new table with both keys (plus attributes of the relationship, such as Score).
  4. 1:1 → a foreign key on either side (often the side with total participation).

Why normalise

Badly designed tables cause anomalies:

  • Insertion: cannot add a new course until a student takes it.
  • Update: a course title stored in 300 rows must be changed in all 300.
  • Deletion: deleting the last student in a course loses the course's title.

Worked example

Unnormalised: Registration(MatricNo, Name, Dept, DeptHead, Courses: [Code, Title, Units, Score]).
First normal form (1NF): no repeating groups; every cell holds one value. Make one row per student per course:
R(MatricNo, Name, Dept, DeptHead, Code, Title, Units, Score), key (MatricNo, Code).

Second normal form (2NF): 1NF and no partial dependency (a non-key column depending on only part of a composite key).

  • Name, Dept, DeptHead depend on MatricNo alone.
  • Title, Units depend on Code alone.

Split: Student(MatricNo, Name, Dept, DeptHead), Course(Code, Title, Units), Result(MatricNo, Code, Score).

Third normal form (3NF): 2NF and no transitive dependency (a non-key column depending on another non-key column).

  • DeptHead depends on Dept, which depends on MatricNo.

Split: Student(MatricNo, Name, Dept), Department(Dept, DeptHead).

Final tables: Student, Department, Course, Result. Each fact is stored once.

Memory aid: every non-key attribute depends on "the key, the whole key, and nothing but the key".

Beyond 3NF

Boyce-Codd normal form (BCNF) requires every determinant to be a candidate key; it fixes rare cases 3NF misses. Designers sometimes denormalise on purpose for speed in reporting, accepting the redundancy.

Exams usually ask

  • Draw an ER diagram for a scenario (library, hospital, hostel allocation).
  • Normalise a table to 3NF, showing each step and the dependencies.
  • Explain update, insertion and deletion anomalies.

Common mistake

Stopping at 1NF because the table "looks neat". Check every non-key column: does it depend on the whole key and only on the key?

Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.

Read

Watch

We link to free material and never copy it. Every link was opened by our team before it went up; video data is a rough guide at 360p.

All CSC 282 topics

Report

Sign in to report this. It is free.

Is this your work (a lecturer, author or publisher)? Ask us to take it down.