Before writing powerful SQL queries, you need to understand how data is actually stored.
This article explains:
This is Part 02 of the SQL from Zero to Pro series.
A table is where relational databases store data.
Think of a table as a spreadsheet:
customers Table| id | name | country | |
|---|---|---|---|
| 1 | Alice | alice@email.com | UK |
| 2 | Bob | bob@email.com | PT |
Each table usually represents one real-world concept, such as:
A row represents a single record.
In the customers table:
(1, Alice, alice@email.com, UK)
(2, Bob, bob@email.com, PT)
Most tables have a primary key:
id INT PRIMARY KEY
π§ No two rows can share the same primary key value.
A column defines a single attribute of the data.
Examples:
Each column has:
name VARCHAR(100)
Column Rules
A schema is a logical container for tables.
Think of it like:
database
βββ public
βββ users
βββ orders
βββ products
Why Schemas Matter
Schemas help with:
Common SQL Data Types
Data types define what kind of values a column can store.
| Numeric Types | Β |
| Type | Example |
| INT | 42 |
| DECIMAL | 99.99 |
| FLOAT | 3.14 |
| Text Types | Β |
| Type | Example |
| VARCHAR | βAliceβ |
| TEXT | Long descriptions |
| Date & Time Types | Β |
| Type | Example |
| DATE | 2025-07-21 |
| TIMESTAMP | 2025-07-21 10:00 |
| Boolean Type | Β |
| Type | Example |
| BOOLEAN | true / false |
Choosing the right data type affects:
Example
price VARCHAR(10) β
price DECIMAL(10,2) β
Benefits of Correct Data Types
Developers care about:
Common focus areas:
Analysts care about:
Common focus areas:
Given this table definition, identify:
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(100),
price DECIMAL(10,2),
in_stock BOOLEAN
);
Design a table called employees with:
Write the CREATE TABLE statement.
Why is DATE a better choice than VARCHAR for a birth date?
Write your answer in plain English.
Create a table locally using SQLite or an online SQL editor and try:
Tables, rows, columns, and data types form the foundation of every relational database.
If you understand:
In the next article (SQL 03), weβll dive into SELECT queries and filtering data, where SQL really starts to feel powerful.
Happy querying π
Given the table definition:
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(100),
price DECIMAL(10,2),
in_stock BOOLEAN
);
Table Name
Columns and Data Types
| Column Name | Data Type | Description |
| id | INT | Unique identifier for each product |
| name | VARCHAR(100) | Name of the product |
| price | DECIMAL(10,2) | Product price with two decimal places |
| in_stock | BOOLEAN | Indicates if the product is available |
Primary Key
id is the primary keyRequirements Recap
Create a table called employees with:
One Possible Solution
CREATE TABLE employees (
id INT PRIMARY KEY,
first_name VARCHAR(100),
last_name VARCHAR(100),
email VARCHAR(255),
hire_date DATE
);
Why These Choices?
INT for id: efficient and commonly indexedVARCHAR for names and email: flexible lengthDATE for hire date: enables date-based queries and sortingQuestion
Why is DATE a better choice than VARCHAR for a birth date?
Answer (Plain English)
Using the DATE data type ensures that:
If dates are stored as βVARCHARβ, the database:
Next up: SQL 03 β SELECT Queries and Filtering Data π