CSC 282 · Database Programming
Our notes
2 min readTerms
| Formal | Everyday | File term |
|---|---|---|
| relation | table | file |
| tuple | row | record |
| attribute | column | field |
| domain | allowed values | field 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
-
Best pick Introduction to Computer Science, 8.3 Relational Database Management Systems
(opens openstax.org in a new tab)
OpenStax, Introduction to Computer Science, 8.3 Relational Database Management Systems, CC BY-NC-SA 4.0 · licence
-
Relational model
(opens en.wikipedia.org in a new tab)
Wikipedia, Relational model, CC BY-SA 4.0 · licence
-
Primary key
(opens en.wikipedia.org in a new tab)
Wikipedia, Primary key, CC BY-SA 4.0 · licence
-
Foreign key
(opens en.wikipedia.org in a new tab)
Wikipedia, Foreign key, CC BY-SA 4.0 · licence
-
NOUN CIT 304: Data Management
NOUN course book (PDF, about 6.9 MB: best on Wi-Fi). Files, databases, the relational model and SQL.
(opens nou.edu.ng in a new tab)
-
OpenStax, Introduction to Computer Science (whole free textbook)
The whole book, free to read online or download as a PDF (the PDF is large: Wi-Fi).
(opens openstax.org in a new tab)
OpenStax, OpenStax, Introduction to Computer Science (whole free textbook), CC BY-NC-SA 4.0 · licence
Watch
-
Introduction to Relational Data Model
7 min · ≈ 32 MB · about ₦18
(opens youtube.com in a new tab)
-
🔑 Relational Database Keys Explained: Primary, Foreign, Candidate & Super Keys
6 min · ≈ 27 MB · about ₦15
(opens youtube.com in a new tab)
-
Database Keys Made Easy - Primary, Foreign, Candidate, Surrogate, & Many More
23 min · ≈ 104 MB · about ₦58
(opens youtube.com in a new tab)
-
Relational Data Model Explained | Tables, Keys, Relationships & Database Design
5 min · ≈ 23 MB · about ₦13
(opens youtube.com in a new tab)
-
#7 Relational Data Model & Notion of Keys | Introduction to Database Systems
49 min · ≈ 221 MB · about ₦124
(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.