Relational Database Concepts
Relational Database Concepts
A focused guide to how relational databases organize data with tables, fields, records, keys, relationships, integrity rules, normalization, indexes, and SQL.
Introduction to Relational Databases
A relational database organizes data into tables. Each table represents a subject or entity, rows represent individual records, and columns represent fields or attributes. Relationships connect records in different tables through keys.
Instead of storing everything in one large block, a relational database separates related subjects into tables and then connects those tables using identifiers. This reduces unnecessary duplication and makes the data easier to query, validate, and maintain.
Table
A collection of related records arranged in rows and columns. Examples: Students, Courses, and Enrollment.
Field / Column
An attribute describing the entity. Examples: StudentID, Name, Email, Program, and CourseCode.
Record / Row
One complete instance stored in a table. One row in Students represents one student.
Relationship
An association between tables, usually created by matching a foreign key to a primary key.
Tables, Fields & Records
The table is the basic storage structure of the relational model. Use this student table to see how rows, columns, and individual values fit together.
| StudentID PK | Name | Program | |
|---|---|---|---|
| 1001 | Alya Rahman | Computer Science | alya@example.edu |
| 1002 | Hafiz Iskandar | Data Analytics | hafiz@example.edu |
| 1003 | Siti Amira | Business | siti@example.edu |
Students
The whole grid represents one table focused on the student entity.
Program
The Program column stores the same kind of attribute for every student record.
Student 1002
The entire row for Hafiz is one record.
Data Analytics
This is one value at the intersection of a record and a field.
Primary & Foreign Keys
Primary keys uniquely identify records. Foreign keys reference primary keys in other tables, creating the links that allow related relational data to be stored separately and combined when needed.
Primary Key (PK)
A field—or combination of fields—whose value uniquely identifies each record. Students.StudentID and Courses.CourseID are primary keys.
UniqueIdentifierForeign Key (FK)
A field containing a reference to a related record. Enrollment.StudentID references Students, while Enrollment.CourseID references Courses.
ReferenceRelationshipVisual Illustration — How the Tables Are Linked
Follow the highlighted record for Hafiz Iskandar (StudentID 1002). Enrollment acts as the linking table between a student and the courses that student takes.
| StudentID (PK) | Name | Program |
|---|---|---|
| 1001 | Alya Rahman | CS |
| 1002 | Hafiz Iskandar | Data Analytics |
| 1003 | Siti Amira | Business |
| 1004 | Kumar Naidu | Engineering |
Uniquely identifies each student.
| EnrollmentID (PK) | StudentID (FK) | CourseID (FK) | Semester |
|---|---|---|---|
| E500 | 1001 | C101 | Fall |
| E501 | 1002 | C101 | Fall |
| E502 | 1002 | C205 | Fall |
| E503 | 1003 | C101 | Fall |
| E504 | 1004 | C220 | Fall |
FKs: StudentID → Students · CourseID → Courses
| CourseID (PK) | CourseName | Credits |
|---|---|---|
| C101 | Database Fundamentals | 3 |
| C205 | Data Management | 3 |
| C220 | Data Visualization | 3 |
| C310 | Analytics Project | 4 |
Uniquely identifies each course.
How the Tables Are Linked
Example SQL Join
Because the key values match, SQL can combine columns from all three tables:
SELECT s.StudentID, s.Name,
c.CourseID, c.CourseName
FROM Students AS s
JOIN Enrollment AS e
ON s.StudentID = e.StudentID
JOIN Courses AS c
ON e.CourseID = c.CourseID
WHERE s.StudentID = 1002;
1002 · Hafiz Iskandar → C101 Database Fundamentals
1002 · Hafiz Iskandar → C205 Data Management
The primary key identifies a record in its own table. A foreign key carries that identifier into another table. Enrollment therefore connects Students and Courses without repeatedly storing the student's or course's full details.
Relationships & Cardinality
Cardinality describes how many records in one table can be associated with records in another table. The three common patterns are one-to-one (1:1), one-to-many (1:M), and many-to-many (M:M).
Pattern 1 — One-to-One (1:1)
One record in the first table relates to only one record in the second table, and vice versa.
Student ↔ Student Profile
Each student has one profile, and each profile belongs to one student.
StudentID
StudentProfile.StudentID references Students.StudentID and is unique in StudentProfile, preventing multiple profiles for the same student.
Pattern 2 — One-to-Many (1:M)
One record in the first table can relate to many records in the second table, but each record on the many side belongs to one record on the one side.
Student → Enrollment
One student can have many enrollment records. Each enrollment record refers to one student.
Student 1002
Hafiz can have enrollment E501 for C101 and E502 for C205. Both rows contain StudentID 1002 as a foreign key.
Pattern 3 — Many-to-Many (M:M)
Many records in the first table can relate to many records in the second table. In a relational database, this is normally implemented using a junction (bridge) table.
Students ↔ Courses
A student can take many courses, and a course can contain many students.
Enrollment Bridge Table
Enrollment stores StudentID and CourseID as foreign keys. Each row represents one student-course association.
| EnrollmentID PK | StudentID FK | CourseID FK |
|---|---|---|
| E501 | 1002 | C101 |
| E502 | 1002 | C205 |
| E503 | 1003 | C101 |
1:1: one student → one profile. 1:M: one student → many enrollment records. M:M: many students ↔ many courses, resolved through the Enrollment junction table.
Download the SQLite database used in these examples. It contains the Students, Enrollment, and Courses tables, including primary keys, foreign keys, indexes, and cascade rules.
↓ Download SQLite Sample Database
SQLite file · 3 linked tables · Foreign-key constraints enabled in the schema
Referential Integrity
Referential integrity protects relationships between tables. A foreign-key value should refer to an existing primary-key value. Use the animation below to see what happens when references are valid, broken, updated, or deleted.
Valid Reference
A foreign key matches an existing primary key. Example: Enrollment.StudentID 1002 points to Students.StudentID 1002.
Orphaned Record
A child record points to a parent record that does not exist. This broken relationship is what referential-integrity rules are designed to prevent.
Cascade Update
If a referenced key changes, cascade update propagates the new key value to related foreign-key records.
Cascade Delete
If a parent record is deleted, cascade delete automatically removes related child records. This can also remove dependent history, so it must be used carefully.
Interactive Referential Integrity Demonstration
Start with Student 1002 and two Enrollment records that reference that student. Select a concept to animate the relationship.
Valid: PK and FK match. Orphan: the parent disappears while child references remain. Cascade update: changing PK 1002 → 2002 also changes both foreign keys. Cascade delete: deleting the parent also removes the dependent enrollment rows.
Normalization
Normalization reorganizes relational data to reduce unnecessary duplication and improve integrity. The example below begins with a denormalized student table and progressively restructures it into First, Second, and Third Normal Form.
Starting Point — Denormalized Students Table
This table mixes student, program, and course information in one place. Course values repeat across columns, while student and program details are duplicated whenever a student has multiple courses.
| StudentID | StudentName | ProgramID | ProgramName | Course1 | Course1Name | Course2 | Course2Name |
|---|---|---|---|---|---|---|---|
| 1002 | Hafiz Iskandar | P20 | Data Analytics | C101 | Database Fundamentals | C205 | Data Management |
| 1003 | Siti Amira | P30 | Business | C101 | Database Fundamentals | C310 | Analytics Project |
Repeating groups: Course1/Course2. Redundancy: course and program names may appear repeatedly. Update risk: changing a course or program name may require editing many rows.
Interactive Transition: Denormalized → 1NF → 2NF → 3NF
Select each stage or use Play Transition to watch the structure improve step by step.
Denormalized
REPEATING GROUPS| StudentID | StudentName | ProgramID | ProgramName | Course1 | Course1Name | Course2 | Course2Name |
|---|---|---|---|---|---|---|---|
| 1002 | Hafiz Iskandar | P20 | Data Analytics | C101 | Database Fundamentals | C205 | Data Management |
| 1003 | Siti Amira | P30 | Business | C101 | Database Fundamentals | C310 | Analytics Project |
First Normal Form (1NF)
ONE VALUE PER FIELD| StudentID | StudentName | ProgramID | ProgramName | CourseID | CourseName |
|---|---|---|---|---|---|
| 1002 | Hafiz Iskandar | P20 | Data Analytics | C101 | Database Fundamentals |
| 1002 | Hafiz Iskandar | P20 | Data Analytics | C205 | Data Management |
| 1003 | Siti Amira | P30 | Business | C101 | Database Fundamentals |
| 1003 | Siti Amira | P30 | Business | C310 | Analytics Project |
Second Normal Form (2NF)
SEPARATE PARTIAL DEPENDENCIESStudents
| StudentID (PK) | StudentName | ProgramID | ProgramName |
|---|---|---|---|
| 1002 | Hafiz Iskandar | P20 | Data Analytics |
| 1003 | Siti Amira | P30 | Business |
Courses
| CourseID (PK) | CourseName |
|---|---|
| C101 | Database Fundamentals |
| C205 | Data Management |
| C310 | Analytics Project |
Enrollment
| StudentID (FK) | CourseID (FK) |
|---|---|
| 1002 | C101 |
| 1002 | C205 |
| 1003 | C101 |
| 1003 | C310 |
Third Normal Form (3NF)
REMOVE TRANSITIVE DEPENDENCYStudents
| StudentID (PK) | StudentName | ProgramID (FK) |
|---|---|---|
| 1002 | Hafiz Iskandar | P20 |
| 1003 | Siti Amira | P30 |
Programs
| ProgramID (PK) | ProgramName |
|---|---|
| P20 | Data Analytics |
| P30 | Business |
Courses
| CourseID (PK) | CourseName |
|---|---|
| C101 | Database Fundamentals |
| C205 | Data Management |
| C310 | Analytics Project |
Enrollment
| StudentID (FK) | CourseID (FK) |
|---|---|
| 1002 | C101 |
| 1002 | C205 |
| 1003 | C101 |
| 1003 | C310 |
What Changes at Each Stage?
Repeating Data
Course1, Course2, duplicated descriptions
Atomic Rows
One course per student-course row
Split by Key
Students, Courses, Enrollment
Split Dependencies
Programs becomes a separate table
Normalization separates data into related tables to reduce redundancy and improve integrity. Denormalization intentionally combines some data again, often for reporting, analytics, or situations where simpler/faster reads are more important than eliminating every repeated value.
Indexes, SQL & ACID
Relational databases are more than tables. Indexes help locate records efficiently, SQL is used to work with relational data, and ACID principles describe reliable transaction behavior.
Indexing
An index helps the database locate matching records without examining every row. Primary keys are commonly indexed automatically.
SQL
Structured Query Language is used to retrieve and manipulate relational data. Queries can join related tables so separate data appears together in a result.
Animation: Table Scan vs. Indexed Lookup
Find StudentID 1005. Compare checking rows one by one with using an index to jump to the matching record.
1001→ row 11002→ row 21003→ row 31004→ row 41005→ row 51006→ row 6Animation: SQL JOIN in Action
Run the query to see SQL filter StudentID 1002, match the foreign key, and combine data from two related tables.
Example: joining student and enrollment data
SELECT s.StudentID, s.Name, e.CourseID, e.Semester FROM Students AS s JOIN Enrollment AS e ON s.StudentID = e.StudentID WHERE s.StudentID = 1002;
The JOIN uses the relationship between Students.StudentID and Enrollment.StudentID to combine columns from both tables.
Animation: ACID Transaction in Action
Transfer $100 from Account A to Account B. Watch the four ACID principles support a reliable database transaction.
Account A
Account B
Atomicity
A transaction is treated as all-or-nothing: all required changes complete, or the transaction does not complete.
Consistency
A transaction must preserve the database's defined validity and integrity rules.
Isolation
Concurrent transactions should not interfere with each other or expose incomplete work.
Durability
Once a transaction is committed, its changes persist even after a failure or restart.
Relational Database Summary
Use this map to connect the major ideas rather than memorizing each term in isolation.
Entity → Table → Record → Field → Primary Key → Foreign Key → Relationship → Referential Integrity. Normalization determines how the tables are organized; cardinality describes how records relate; indexes improve lookup efficiency; SQL retrieves and combines the data; ACID principles support reliable transactions.
Storage
Tables contain rows (records) and columns (fields).
Identity
Primary keys uniquely identify records.
Connection
Foreign keys connect related tables.
Quality
Normalization and referential integrity help protect consistency.
Knowledge Check — 20 Quiz Questions
Test your understanding of tables, keys, relationships, referential integrity, normalization, indexes, SQL, and ACID. Choose one answer for each question, then submit to see your score.
1. Which statement best defines a relational database?
Relational databases organize data into tables and use keys to connect related records.
2. In a Students table, what does one row normally represent?
A row represents one record—in this example, one student.
3. What is the main purpose of a primary key?
A primary key provides a unique identifier for each record.
4. Which field in Enrollment is a foreign key referencing Students?
Enrollment.StudentID points to Students.StudentID.
5. Which field in Enrollment can reference Courses.CourseID?
Enrollment.CourseID stores the identifier of a related course.
6. If one student can have many enrollment records, the relationship is:
One Students record can be referenced by multiple Enrollment records.
7. How is a many-to-many Students–Courses relationship implemented in the examples?
Enrollment acts as the junction table linking students and courses.
8. What does referential integrity require for a foreign-key value?
Referential integrity keeps references valid by requiring matching referenced keys.
9. What is an orphaned record?
An orphan occurs when a child still references a parent record that no longer exists.
10. What does ON UPDATE CASCADE demonstrate?
Cascade update propagates the changed parent key to dependent foreign-key values.
11. What does ON DELETE CASCADE do in the lesson example?
Cascade delete removes dependent child rows along with the referenced parent.
12. What is the main problem with Course1 and Course2 columns in the denormalized example?
Course1 and Course2 are repeating groups, making the design harder to extend.
13. What key change is illustrated when moving to First Normal Form (1NF)?
The 1NF illustration removes repeating course columns and uses one course value per row.
14. In the 1NF example, which pair can identify a student-course row?
The example uses the composite key StudentID plus CourseID to identify a student-course occurrence.
15. What happens in the illustrated transition to Second Normal Form (2NF)?
The 2NF stage separates student details, course details, and their linking records.
16. Why is Programs separated from Students in the illustrated Third Normal Form (3NF) stage?
ProgramName is determined by ProgramID, so the Programs data is separated.
17. What is the purpose of an index?
Indexes are data structures used to improve lookup and query access.
18. Which SQL operation combines related rows from Students and Enrollment using matching keys?
JOIN combines related rows by matching key values such as StudentID.
19. Which ACID property means a transaction is all-or-nothing?
Atomicity means the transaction completes as a unit or does not take effect.
20. Which ACID property means committed changes persist?
Durability means committed transaction results persist.