Lesson 1.3 · Reading time: ~10 min
A relational database organizes data into tables connected by keys. In this lesson you will learn the core building blocks — tables, columns, rows, primary keys, foreign keys, unique keys, and constraints — and discover how the ACID model keeps transactions safe and reliable even under concurrent access or system failure.
In the previous lessons, we introduced the concept of databases and looked at the main database types. Now we'll dive deeper into the core components of relational databases, which are fundamental to understanding how data is organized and accessed using SQL.

Relational databases organize data into structures called tables. Think of a table as a spreadsheet:
Example:
Let's visualize a simple "Customers" table:
| CustomerID | FirstName | LastName | |
|---|---|---|---|
| 1 | John | Doe | john.doe@example.com |
| 2 | Jane | Smith | jane.smith@example.com |
| 3 | David | Lee | david.lee@example.com |
Keys are a critical concept in relational databases. They are used to establish relationships between tables and enforce data integrity. Here are the main types of keys:
A constraint is a rule applied to a column or table that the database engine enforces automatically. Keys (primary, foreign, unique) are a type of constraint. There are several other important constraints you will use in everyday SQL:
| Constraint | Purpose |
|---|---|
NOT NULL | The column must always have a value; NULL is not allowed. |
UNIQUE | All values in the column must be distinct across rows. |
PRIMARY KEY | Combines NOT NULL + UNIQUE; uniquely identifies each row. |
FOREIGN KEY | Value must match an existing value in another table's column. |
CHECK | Value must satisfy a specified condition, e.g. age >= 0. |
For example, in a customers table:
customer_id can act as a PRIMARY KEY, so each customer has a unique identifier.email can be marked as UNIQUE, so two customers cannot share the same email address.age can use a CHECK rule such as age >= 0, so negative ages are rejected.The database automatically enforces these rules and rejects invalid changes, which helps keep data consistent without extra application-level checks.
When working with relational databases, another core concept is the ACID model. ACID defines the properties that make database transactions safe and reliable.
A transaction is a group of operations treated as one unit of work. For example, transferring money between two bank accounts usually involves at least two operations:
Both steps must succeed together, or neither should be applied.
ACID stands for:
These properties are essential in real-world systems such as banking, e-commerce, and inventory management, where incorrect or partial updates can cause serious problems.
Key takeaways from this lesson:
NOT NULL, CHECK) enforce data rules at the database level automatically.In the next lesson, we will look at the basic data types used in relational databases and how to choose the right type for each column.
A primary key uniquely identifies each row and cannot be NULL. A table can have only one primary key. A unique key also enforces uniqueness but can allow NULL values, and a table can have multiple unique keys. Use a primary key as the main row identifier; use unique keys to enforce uniqueness on other columns such as email.
Yes. A foreign key can reference any column (or set of columns) that has a unique constraint, not just the primary key. However, referencing the primary key is the most common and recommended practice.
Atomicity ensures the entire transaction is rolled back, leaving the database in the state it was before the transaction started. No partial changes are saved.
A primary key is a column or combination of columns that uniquely identifies every row in a table. It must be unique, cannot contain NULL values, and there can be only one per table. It is used as the anchor for foreign key references from other tables.
Referential integrity means that a foreign key value in one table must always match an existing primary key value in the referenced table, or be NULL. The database engine enforces this automatically — attempts to insert an orphaned foreign key value or delete a referenced row will be rejected unless a cascade rule is defined.
ACID stands for Atomicity, Consistency, Isolation, and Durability. It defines the guarantees that make database transactions reliable. Without ACID, concurrent writes could corrupt data, partial failures could leave the database in an invalid state, and committed changes could be lost after a crash. ACID is why relational databases are trusted for financial, medical, and other critical systems.