What Is a Database?
If you've ever kept a list of contacts in a notes app, a JSON file, or a spreadsheet, you've already felt the pain points: duplicates, inconsistent formats, and "Where did that row go?"
A database is a system for storing and retrieving data so it stays organized, consistent, and easy to search as it grows.
Core Concepts
At a high level, a database helps you do four things reliably:
- Create data
- Read data
- Update data
- Delete data
flowchart TD
A[Your App Needs Data] --> B{How complex is it?}
B -->|Small + simple| C[File (JSON / text)]
B -->|Manual editing| D[Spreadsheet]
B -->|Querying + integrity + growth| E[(Database)]
E --> F[SQL queries]
E --> G[Constraints keep data consistent]
Database vs DBMS
People often say "database" when they mean two different things:
| Term | Meaning | Example |
|---|---|---|
| Database | The stored data (and its structure) | app.db |
| DBMS | The software that manages the database | SQLite, PostgreSQL, MySQL |
Why Not Just Use Files or Spreadsheets?
| Option | Great for | Pain points as you grow |
|---|---|---|
| Text/JSON files | Very small datasets; config; single-purpose storage | Hard to query; easy to corrupt; integrity is "on you" |
| Spreadsheets | Manual entry; quick summaries; sharing with non-devs | No strong constraints; merges are painful; automation gets messy |
| Databases | Apps that need reliable querying and consistency | Requires learning schema + SQL (worth it) |
Code Examples
SQL results are always shaped like a table: columns and rows.
-- A "result set" is tabular: rows and columns.
-- We are not creating a real table yet; this is just a quick example.
SELECT
'Ada Lovelace' AS name,
'ada@example.com' AS email;
| name | |
|---|---|
| Ada Lovelace | ada@example.com |
SQLite-Specific Nuances
With SQLite, a database is typically a single file on disk.
- Your application reads and writes that file through the SQLite library
- Moving a SQLite database can be as simple as moving the
.dbfile
Common Pitfalls / Best Practices
Confusing a database with a spreadsheet.
A spreadsheet is optimized for human editing; a database is optimized for consistency, automation, and reliable querying.
Use a database when you need at least one of these:
- Reliable querying (filtering, sorting, combining data)
- Consistency rules (like "email must be unique")
- Multiple parts of an app reading/writing the same data
Quick Challenge
Write a query that returns one row with two columns:
toolset todatabasebenefitset toqueryable
View Solution
-- Two columns, one row.
SELECT
'database' AS tool,
'queryable' AS benefit;
| tool | benefit |
|---|---|
| database | queryable |