UNIHIVE

Study Hub UNIPORT CSC 480

CSC 480 · Database Management

The relational model, keys and integrity

Relations, tuples, attributes and domains, properties of relations, superkeys, candidate, primary, alternate and foreign keys, nulls, entity and referential integrity, and views.

Our notes

2 min read

Terms

FormalInformalFile term
Relationtablefile
Tuplerowrecord
Attributecolumnfield
Domainallowed values of a column
Degreenumber of attributes
Cardinalitynumber of tuples

The relation schema is written Student(MatNo, FirstName, Surname, Level, DeptCode).

Properties of a relation

Each cell holds one atomic value; attribute names are distinct; values of an attribute come from one domain; no duplicate tuples; order of tuples and of attributes does not matter.

Keys

  • Superkey: a set of attributes that uniquely identifies a tuple (MatNo; MatNo + Surname).
  • Candidate key: a minimal superkey (no attribute can be removed). A student may have two: MatNo and JAMB RegNo.
  • Primary key: the candidate key chosen to identify tuples (MatNo).
  • Alternate key: a candidate key not chosen (JAMB RegNo; enforce it with UNIQUE).
  • Composite key: made of several attributes (MatNo + CourseCode + Session in Registration).
  • Foreign key: attribute(s) in one relation that match the primary key of another (Student.DeptCode refers to Department.DeptCode).
  • Surrogate key: an artificial key (an auto-increment id) used when natural keys are long or may change.

Nulls

NULL means "unknown" or "not applicable", not zero or empty text. Comparisons with NULL are unknown, so SQL uses IS NULL, not = NULL.

Integrity rules

  • Entity integrity: no part of a primary key may be NULL.
  • Referential integrity: a foreign key value must match an existing primary key value in the referenced table, or be NULL (if allowed).
  • Domain constraints: values must be in the domain (Score BETWEEN 0 AND 100; Level IN (100, 200, 300, 400, 500)).
  • General constraints (business rules): a student may register at most 24 units a semester.

What happens when a referenced row is deleted? ON DELETE RESTRICT (refuse), CASCADE (delete dependants too), SET NULL, SET DEFAULT.

Views

A view is a virtual table defined by a query. It gives each user group its own external view (the hostel office sees name, level and hall, not results), hides complexity and adds security. Updating through views is restricted (a view over a join or with aggregates is usually read-only).

Exams usually ask: define the relational terms; properties of relations; kinds of keys with examples; entity and referential integrity; referential actions on delete; uses of views.

Common mistake: saying a foreign key must be unique. It need not be: many students share the same DeptCode. It must only match an existing primary key (or be null).

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 480 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.