UNIHIVE

Study Hub UNIPORT CSC 282

CSC 282 · Database Programming

The relational model: tables, keys and relationships

Relations, attributes and tuples, primary and foreign keys, integrity rules and the kinds of relationship.

Our notes

2 min read

Terms

FormalEverydayFile term
relationtablefile
tuplerowrecord
attributecolumnfield
domainallowed valuesfield type

A table has no duplicate rows, and the order of rows and columns carries no meaning.

Keys

  • Super key: any set of columns that identifies a row uniquely.
  • Candidate key: a minimal super key (nothing can be removed). Students: MatricNo, and perhaps JAMBRegNo.
  • Primary key: the candidate key chosen as the main identifier.
  • Composite key: a key of two or more columns: (MatricNo, CourseCode, Session) in a Results table.
  • Foreign key: a column whose values must match a primary key in another table.

Example schema

  • Student(MatricNo, Surname, OtherNames, DeptCode, Level)
  • Department(DeptCode, DeptName, Faculty)
  • Course(CourseCode, Title, Units)
  • Result(MatricNo, CourseCode, Session, Score)

Student.DeptCode is a foreign key to Department; Result.MatricNo and Result.CourseCode are foreign keys to Student and Course.

Integrity rules

  • Entity integrity: no part of a primary key may be NULL.
  • Referential integrity: every foreign key value must match an existing primary key (or be NULL if allowed). You cannot record a result for MatricNo U2023/999 if no such student exists.
  • Domain constraints: Score between 0 and 100; Units 1 to 6.

On delete of a referenced row the DBMS can restrict (refuse), cascade (delete the dependent rows too) or set null.

Relationships

  • One-to-one (1:1): a student has one hostel bed space this session.
  • One-to-many (1:N): a department has many students; each student belongs to one department. The foreign key goes on the many side.
  • Many-to-many (M:N): students take many courses; courses have many students. It needs a linking table (Result or Registration) holding both keys.

Relational algebra (the ideas behind SQL)

  • Selection (σ): choose rows (Level = 200).
  • Projection (π): choose columns (Surname, CGPA).
  • Join (⋈): combine rows of two tables on matching values.
  • Union, intersection, difference of compatible tables.

Exams usually ask

  • Define the kinds of key with examples.
  • Explain entity and referential integrity.
  • Show how an M:N relationship is represented.

Common mistake

Putting a list in one cell (CoursesTaken = "CSC 280, STA 260, MTH 210"). Each value belongs in its own row of a linking table.

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.