Learn computing fundamentals, programming, algorithms, systems, and software engineering.
A database is an organised collection of data, and a Database Management System (DBMS) is the software that stores, queries, and protects it. Most applications store data in a relational database, where information lives in tables with rows and columns and is linked by keys. This lesson covers how to model real-world data as tables, how to normalise a schema to remove duplication, how to query and join tables with SQL, why indexes speed up reads, and what the ACID guarantees mean for reliability. By the end you will be able to design a small relational schema and write the SQL to answer real questions about it.
A relational database stores data in tables. Each table has rows (records) and columns (fields). A primary key uniquely identifies each row; a foreign key references a row in another table.
| Concept | Meaning |
|---|---|
| Table | A collection of related records |
| Row | One record |
| Column | One field of a record |
| Primary key | Uniquely identifies a row |
| Foreign key | References a primary key in another table |
| Relationship | Example |
|---|---|
| One-to-one | A person has one passport |
| One-to-many | One customer has many orders |
| Many-to-many | Students enrolled in many courses |
Normalization removes duplicate data and dependency problems by reshaping tables. It is not about memorising rules — it is about asking "what fact depends on what key?"
A JOIN combines rows from two tables based on a matching condition.
| Join | Returns |
|---|---|
| INNER JOIN | Only rows with matches in both tables |
| LEFT JOIN | All left rows, plus matches (null where none) |
Aggregate functions summarise groups of rows: COUNT, SUM, AVG, MIN, MAX. GROUP BY forms the groups; HAVING filters them after aggregation.
An index is a data structure that lets the database find rows without scanning the whole table. It speeds up reads but slows down writes and uses extra space, so add indexes only on columns you search or join on often.
A transaction is a group of operations that must all succeed or all fail together. ACID are the guarantees that make transactions safe.
| Property | Meaning |
|---|---|
| Atomicity | All-or-nothing |
| Consistency | Valid state before and after |
| Isolation | Concurrent transactions do not interfere |
| Durability | Committed changes survive crashes |
A money transfer that debits one account and credits another is the classic example: either both happen or neither does.
This query computes total revenue per user by joining the four tables.
Count products priced above 20.
3
List each order with the customer name.
1 Ada 2 Bob