🗄️ Lesson 1: What Is a Database?
Before you write a single line of SQL, let's understand what databases are, why they exist, and how relational databases organize information into tables, rows, and columns.
🎯 Learning Objectives
By the end of this lesson, you will be able to:
- Explain what a database is and why applications need one
- Distinguish between different types of databases (relational vs. non-relational)
- Define key relational database terminology: table, row, column, primary key
- Describe what SQL is and what it's used for
- Explain why MySQL is a popular choice for web development
Estimated Time: 30 minutes
📑 In This Lesson
Why Do We Need Databases?
Imagine you run a small online store. You need to keep track of your products, your customers, and every order that comes in. Where do you put all that information?
You could use a spreadsheet. And for a handful of products and a few customers, that might work fine. But what happens when you have 10,000 products, 50,000 customers, and hundreds of orders per day? Spreadsheets start to break down:
- Duplicate data everywhere — the same customer address copied into every order row
- No rules enforced — nothing stops someone from entering "abc" in a price field
- Slow searches — finding all orders from last Tuesday means scanning every row
- No multi-user access — two people editing the same file leads to conflicts
- No security — everyone who opens the file sees everything
A database solves all of these problems. At its core, a database is an organized collection of data that is stored, managed, and retrieved electronically. But it's much more than just storage — a database also provides:
📖 What a Database Provides
- Structure — data is organized into well-defined formats
- Integrity — rules ensure data stays valid and consistent
- Efficiency — indexes and query optimizers make searches fast, even across millions of rows
- Concurrency — multiple users can read and write data at the same time
- Security — permissions control who can see or change which data
- Durability — data survives crashes, power failures, and hardware problems
A Database Management System (DBMS) is the software that creates, manages, and provides access to a database. When people say "MySQL" or "PostgreSQL," they're referring to a DBMS. The database itself is the data; the DBMS is the program that manages it.
(website, app, script)"] -->|"SQL queries"| B["DBMS
(MySQL)"] B -->|"reads/writes"| C["Database
(your data on disk)"] B -->|"results"| A
Types of Databases
Not all databases work the same way. The two main categories you'll encounter are relational and non-relational databases.
Relational Databases (SQL)
Relational databases store data in tables with predefined columns and data types — much like a well-organized spreadsheet. The key difference is that tables can be related to each other through shared keys. This is the type of database you'll learn in this course.
Popular relational databases include:
- MySQL — open-source, widely used in web development (what we'll learn)
- PostgreSQL — open-source, known for advanced features and standards compliance
- SQLite — lightweight, file-based, great for mobile apps and small projects
- Microsoft SQL Server — enterprise-focused, common in corporate environments
- Oracle Database — enterprise-grade, used in large-scale business applications
Non-Relational Databases (NoSQL)
Non-relational databases (often called NoSQL) store data in formats other than tables — documents, key-value pairs, graphs, or wide columns. They're designed for specific use cases where the rigid structure of tables isn't ideal.
Popular non-relational databases include:
- MongoDB — stores data as JSON-like documents
- Redis — in-memory key-value store, extremely fast
- Firebase — real-time document database by Google
- Neo4j — graph database for relationship-heavy data
💡 Which Type Should You Learn?
For web development, relational databases are the foundation. The vast majority of web applications — WordPress, Shopify, most business apps — run on relational databases. Once you understand relational concepts and SQL, picking up a NoSQL database later is straightforward. That's why this course focuses entirely on MySQL.
Comparison at a Glance
| Feature | Relational (SQL) | Non-Relational (NoSQL) |
|---|---|---|
| Data format | Tables with rows and columns | Documents, key-value, graphs |
| Schema | Fixed — defined before inserting data | Flexible — can vary per record |
| Query language | SQL (standardized) | Varies by database |
| Relationships | Built-in (foreign keys, joins) | Typically handled in application code |
| Best for | Structured data, complex queries, transactions | Unstructured data, horizontal scaling, real-time apps |
| Examples | MySQL, PostgreSQL, SQLite | MongoDB, Redis, Firebase |
Relational Databases Up Close
Since this entire course is about relational databases, let's make sure the core vocabulary is crystal clear. Every term here will come up again and again.
Tables
A table (sometimes called a relation) is a collection of related data organized into rows and columns. Each table represents one type of thing — customers, products, orders, employees, etc.
Columns (Fields)
A column defines a single piece of information that every row in the table must have. Each column has a name and a data type (text, number, date, etc.). Think of columns as the headers in a spreadsheet.
Rows (Records)
A row (also called a record) is one entry in the table — one customer, one product, one order. Each row contains a value for every column.
Primary Key
A primary key is a column (or combination of columns) whose value uniquely identifies each row. No two rows can have the same primary key, and it can never be empty. The most common pattern is an auto-incrementing integer ID.
Putting It All Together
Here's what a customers table might look like:
| id (PK) | first_name | last_name | city | |
|---|---|---|---|---|
| 1 | Maria | Santos | maria@email.com | Manila |
| 2 | James | Chen | james@email.com | Taipei |
| 3 | Aiko | Tanaka | aiko@email.com | Tokyo |
In this table:
- The table name is
customers - There are 5 columns: id, first_name, last_name, email, city
- There are 3 rows (three individual customers)
- The primary key is the
idcolumn — each value (1, 2, 3) is unique
📖 Key Terminology Quick Reference
- Database — a collection of related tables
- Table — a structured set of rows and columns storing one type of data
- Column / Field — a named attribute with a data type (e.g.,
email VARCHAR(255)) - Row / Record — a single entry in a table
- Primary Key (PK) — a column that uniquely identifies each row
- Schema — the blueprint that defines a database's tables, columns, and relationships
What Is SQL?
SQL (Structured Query Language, often pronounced "sequel") is the standard language for communicating with relational databases. When you want to create a table, insert data, search for records, update values, or delete rows, you write SQL statements to tell the database what to do.
SQL has been around since the 1970s and is used by virtually every relational database in existence. While each database (MySQL, PostgreSQL, SQLite) has minor dialect differences, the core SQL syntax is the same everywhere. Learn it once, and you can work with any relational database.
The Four Main Operations: CRUD
Most of what you'll do with SQL falls into four categories, often referred to by the acronym CRUD:
| Operation | SQL Command | What It Does |
|---|---|---|
| Create | INSERT |
Add new rows to a table |
| Read | SELECT |
Retrieve data from one or more tables |
| Update | UPDATE |
Modify existing rows |
| Delete | DELETE |
Remove rows from a table |
A Taste of SQL
Don't worry about memorizing any of this yet — you'll learn each command in detail in later lessons. For now, just get a feel for what SQL looks like:
-- Create a table
CREATE TABLE customers (
id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(100),
city VARCHAR(50)
);
-- Insert a row
INSERT INTO customers (first_name, last_name, email, city)
VALUES ('Maria', 'Santos', 'maria@email.com', 'Manila');
-- Read data
SELECT first_name, last_name, city
FROM customers
WHERE city = 'Manila';
-- Update a row
UPDATE customers
SET city = 'Quezon City'
WHERE id = 1;
-- Delete a row
DELETE FROM customers
WHERE id = 3;
✅ Key Insight
Notice how SQL reads almost like English: "SELECT first_name FROM customers WHERE city equals Manila." This readability is one of SQL's greatest strengths — it's one of the most approachable programming languages you'll ever learn.
Beyond CRUD: Other SQL Capabilities
SQL can do much more than basic CRUD. Throughout this course you'll also learn to:
- Define structure — create databases, tables, indexes, and views
- Enforce rules — set constraints like "this column can't be empty" or "this value must be unique"
- Join tables — combine data from multiple related tables in a single query
- Aggregate data — calculate totals, averages, counts, and more
- Control access — grant or revoke permissions for different users
- Manage transactions — group operations so they either all succeed or all fail
Why MySQL?
There are many relational databases to choose from, so why learn MySQL specifically?
- Most popular open-source database — MySQL powers a huge share of the web. WordPress, Drupal, Joomla, and countless custom applications run on it.
- Free and open-source — the Community Edition is completely free to download, use, and deploy.
- Part of the LAMP stack — Linux, Apache, MySQL, PHP is one of the most common web development stacks in the world. Learning MySQL slots perfectly into this ecosystem.
- Huge community — decades of tutorials, Stack Overflow answers, books, and tools.
- Industry demand — MySQL skills are sought after in job postings for web developers, backend engineers, and database administrators.
- Proven at scale — companies like Facebook, Twitter, YouTube, Netflix, and Airbnb use (or have used) MySQL in production.
💡 MySQL vs. MariaDB
You may hear about MariaDB, which is a fork of MySQL created by MySQL's original developer after Oracle acquired MySQL. MariaDB is highly compatible with MySQL — most SQL you write for one works on the other. Everything in this course applies to MariaDB as well.
Operating System"] A --> C["Apache
Web Server"] A --> D["MySQL
Database"] A --> E["PHP
Programming Language"] style D fill:#3b82f6,stroke:#1e40af,color:#fff
MySQL is the "M" in the LAMP stack — you're learning one of the core pillars of web development.
Real-World Example: An Online Bookstore
Let's tie everything together with a concrete example. Imagine you're building a database for an online bookstore. You'd need to track books, customers, and orders. Here's how that might break down into tables:
Notice how the tables are related to each other:
- Each order belongs to one customer (via
customer_id) - Each order can contain multiple order items
- Each order item references one book (via
book_id)
This is the power of a relational database — instead of repeating the full customer address in every order, you store the customer once and just reference their ID. Instead of repeating the book title and price in every order, you reference the book's ID. This eliminates redundancy and keeps your data clean.
⚠️ Don't Worry About the Details Yet
If the diagram above looks complex, that's perfectly normal. You'll learn every piece of it step by step: creating tables in Lesson 4, data types in Lesson 5, relationships in Lesson 11, and foreign keys in Lesson 12. For now, just notice the pattern: separate tables connected by shared IDs.
Exercises
🏋️ Exercise 1: Identify the Parts
Look at this table and identify each component:
| id | title | author | price | in_stock |
|---|---|---|---|---|
| 1 | Noli Me Tangere | José Rizal | 12.99 | true |
| 2 | Dune | Frank Herbert | 15.99 | true |
| 3 | Neuromancer | William Gibson | 11.49 | false |
Answer these questions:
- What is the name of this table?
- How many columns does it have? Name them.
- How many rows does it have?
- Which column is most likely the primary key? Why?
✅ Solution
- The table could be called
books(since each row represents a book). - It has 5 columns:
id,title,author,price,in_stock. - It has 3 rows (three individual books).
- The
idcolumn is the primary key — each value is unique (1, 2, 3), and it serves no purpose other than identifying the row.
🏋️ Exercise 2: Design Your Own Table
Think of a real-world collection of data — your favorite movies, a list of recipes, a roster of game characters, a music playlist, etc.
On paper or in a text file, sketch out a table:
- Give your table a name (e.g.,
movies,recipes,characters) - Define 4–6 columns with names that describe each piece of information
- Fill in 3–5 example rows
- Decide which column is the primary key
💡 Hint
If you're stuck, try a video_games table with columns like: id, title, platform, genre, release_year, rating.
✅ Example Solution
Table name: video_games
| id (PK) | title | platform | genre | release_year | rating |
|---|---|---|---|---|---|
| 1 | Elden Ring | PC | Action RPG | 2022 | 9.5 |
| 2 | Stardew Valley | Switch | Simulation | 2016 | 9.0 |
| 3 | Hades | PC | Roguelike | 2020 | 9.3 |
Primary key: id — unique integer that identifies each game.
🎯 Quick Quiz
Question 1: What does DBMS stand for?
Question 2: Which column in a table uniquely identifies each row?
Question 3: What does CRUD stand for?
Question 4: Which SQL command is used to retrieve data from a table?
Summary
🎉 Key Takeaways
- A database is an organized collection of data managed by a DBMS (like MySQL)
- Relational databases store data in tables with rows and columns, connected by shared keys
- Key terms: table, column/field, row/record, primary key, schema
- SQL is the standard language for working with relational databases
- CRUD (Create, Read, Update, Delete) describes the four basic data operations
- MySQL is open-source, free, widely used, and the "M" in the LAMP stack
📚 Additional Resources
- MySQL Official Docs — What Is MySQL?
- W3Schools — Introduction to MySQL
- Wikipedia — Relational Database
🚀 What's Next?
Now that you understand what databases are and why they matter, it's time to get your hands dirty. In the next lesson, you'll install MySQL on your machine using the LAMP stack and verify that everything is running. Let's go!
🎉 Congratulations!
You've completed Lesson 1. You now know the fundamentals of what databases are, how relational databases organize data, and what SQL is all about. Onward!