What is a database?
Where apps store data permanently
⏱ Est. ~5 min
01 · Read
Every app you use stores data somewhere. When you create an account, post a photo, save a document — that info needs to live somewhere permanent so it's still there when you come back tomorrow.
That's what a database does: an organized system for storing and retrieving data. Without a database, every app would forget everything the moment you closed it.
💡 Picture thisA database is like a neatly organized pantry with labeled shelves. You don't just throw ingredients into a cupboard — you put canned goods on one shelf, spices on another, grains on a third. When you need something, you know where to look. A database does the same thing with data — keeping everything organized so apps can find it instantly.
Key points
- A database stores data permanently — it survives restarts, crashes, and power outages
- Data is organized into structured collections (like tables with rows and columns)
- Apps constantly read from and write to databases as users do things
- Most apps have at least one database running behind the scenes
02 · Code example
Here's what data inside a typical database looks like. This is a users table — each row is a user, each column is a piece of info about them.
users table
| id | name | email | created_at |
|----|------------|--------------------|---------------------|
| 1 | Sara Chen | sara@email.com | 2024-01-15 09:30:00 |
| 2 | Alex Kim | alex@email.com | 2024-02-20 14:45:00 |
| 3 | Jamie Diaz | jamie@email.com | 2024-03-01 11:00:00 |
Each user gets their own row. The columns (id, name, email, created_at) are the same for everyone — that structure is called a schema. Just like a spreadsheet, every row follows the same format.
03 · Read
Not all databases work the same way. There are two main families: SQL databases (like PostgreSQL, MySQL) store data in strict tables with rows and columns. Every row follows the same structure, called a schema. Think of a spreadsheet — every row has exactly the same columns. SQL databases are great when data is predictable and structured.
NoSQL databases (like MongoDB) are more flexible. Instead of rigid tables, they store data as documents — think of them as JSON files. Each document can have different fields, so you don't have to decide on a structure up front. NoSQL is a good fit when data varies a lot or changes often.
Key points
- SQL databases use strict tables with a fixed schema (every row has the same columns)
- NoSQL databases use flexible documents, where each one can have different fields
- PostgreSQL is a popular SQL database; MongoDB is a popular NoSQL database
- Neither is "better" — they're designed for different situations
04 · Drag to sort
Sort these descriptions into the right database type.
(This section is interactive — please enable JavaScript.)
05 · Quiz
Why does an app need a database?
- To store data permanently, so it isn't lost when the app closes
- To make the app look better
- To connect to the internet
- To make the program run faster
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.