Tables, Rows
& Schemas
Master the foundational building blocks of every relational database: how data is organized into tables, rows, columns, and governed by schemas.
What Is a Relational Database?
A relational database is an organized collection of data stored in tables that can relate to each other. Think of it as a collection of spreadsheets, but with strict rules that keep your data consistent and reliable.
The Table: Your Data Container
A table stores data about one kind of thing. Each table has a name (like students) and is made up of columns and rows.
Rows, Columns & Cells
What Is a Schema?
A schema is the blueprint of your database. It defines which tables exist, what columns each table has, and what data type each column accepts: before any data is ever inserted.
Column Data Types
Every column in a schema has a data type that controls what values it can hold. This prevents invalid data from entering your database.
The Primary Key Rule
Every table should have a primary key: a column (or set of columns) whose value is unique for every row. It guarantees that no two rows are identical and gives you a reliable way to find any single record.
Key Distinction: Four Core Concepts
| Concept | Definition | Analogy |
|---|---|---|
| Table | A collection of rows and columns about one entity | A single spreadsheet tab |
| Row | One complete record in the table | One horizontal line of data |
| Column | One attribute shared by all rows | A vertical header category |
| Schema | The blueprint: tables, columns, and their types | The building's floor plan |
Creating a Table with SQL
The CREATE TABLE statement defines a new table in your schema. You specify the table name, each column name, and each column's data type.
How to Design a Table
Example 1: A Books Table
A school library needs to track its books. Let's design a books table.
Example 2: Inserting a Row
Once a table exists, you add data with INSERT INTO. Each insert creates a new row.
Example 3: A Multi-Table Schema
Real databases have multiple tables that relate to each other. Here, enrollments connects students to courses.
Schema vs Data
Common Mistakes to Avoid
Summary: SQL Building Blocks
| Term | What It Is | SQL Command |
|---|---|---|
| Table | A named container for rows and columns | CREATE TABLE |
| Row | A single record (one entry) | INSERT INTO |
| Column | An attribute with a name and data type | Defined in CREATE TABLE |
| Schema | The full blueprint of all tables and types | Collection of CREATE statements |
| Primary Key | Column(s) that uniquely identify each row | PRIMARY KEY constraint |
| Data Type | Rule for what kind of value a column holds | INTEGER, TEXT, REAL, BOOLEAN |
Question 1 of 5
In a relational database, what does a row represent?
Question 2 of 5
What is the purpose of a schema in a database?
Question 3 of 5
Which SQL constraint ensures that no two rows in a table share the same value in a specific column?
Question 4 of 5
A developer creates this table:
CREATE TABLE orders (
order_id INTEGER PRIMARY KEY,
product TEXT NOT NULL,
quantity INTEGER,
price REAL
);
They then try to run:
INSERT INTO orders (order_id, product, quantity, price)
VALUES (1, NULL, 3, 9.99);
What will happen when this INSERT statement runs?
Question 5 of 5
A school database has a students table and a courses table. You need a way to record which students are in which courses. What is the best approach?