CSC 480 · Database Management
Our notes
2 min readTerms
| Formal | Informal | File term |
|---|---|---|
| Relation | table | file |
| Tuple | row | record |
| Attribute | column | field |
| Domain | allowed values of a column | |
| Degree | number of attributes | |
| Cardinality | number 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
-
NOUN CIT 843: Introduction to Database Management Systems
NOUN course book (PDF, about 2 MB). Nigerian course book: database concepts, DBMS architecture, data models, the relational model, SQL, normalisation and transactions.
(opens nou.edu.ng in a new tab)
-
Relational model
(opens en.wikipedia.org in a new tab)
Wikipedia, Relational model, CC BY-SA 4.0 · licence
-
Candidate key
(opens en.wikipedia.org in a new tab)
Wikipedia, Candidate key, CC BY-SA 4.0 · licence
-
Referential integrity
(opens en.wikipedia.org in a new tab)
Wikipedia, Referential integrity, CC BY-SA 4.0 · licence
Watch
-
Best pick Introduction to Relational Data Model
7 min · ≈ 32 MB · about ₦18
(opens youtube.com in a new tab)
-
Keys in RDBMS
23 min · ≈ 104 MB · about ₦58
(opens youtube.com in a new tab)
-
Update Operations/Dealing with Constraint Violations
10 min · ≈ 45 MB · about ₦25
(opens youtube.com in a new tab)
-
Database Design Course - Learn how to design and plan a database for beginners
8 h 7 min · ≈ 2.1 GB · about ₦1,231
(opens youtube.com in a new tab)
-
CS50 SQL - Lecture 1 - Relating
1 h 42 min · ≈ 459 MB · about ₦258
(opens youtube.com in a new tab)
-
#01 - Relational Model & Algebra (CMU Intro to Database Systems)
1 h 15 min · ≈ 338 MB · about ₦190
(opens youtube.com in a new tab)
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.