Databases
Where apps store their data permanently
Introduction
Every app needs to remember things. Instagram remembers your photos and followers. WhatsApp stores your messages. Amazon keeps your order history. But where does all this data live? It lives in a database — a structured system for storing, organizing, and retrieving information.
Without databases, every time you closed an app, everything would be gone. You would have to create a new account, find new friends, and start from scratch each time. Databases are what make data persistent — they remember everything, forever.
In this chapter, you will learn how databases work, the difference between SQL and NoSQL databases, and the four basic operations that every database supports: Create, Read, Update, and Delete — known as CRUD.
How It Works
A database is organized storage. Instead of dumping everything into one big pile, data is structured into tables (for SQL databases) or documents (for NoSQL databases). When the backend needs data, it sends a query to the database, and the database returns the matching results.
Library Analogy
An SQL database is like a library with a card catalog. Every book has a specific place, a specific format, and you must follow the rules to find it. A NoSQL database is like a filing cabinet — each drawer can hold different kinds of documents, and you can organise them however you like.
CRUD Operations
Every database operation falls into one of four categories:
Create
Add new data — a new user, a new post, a new product. Uses the INSERT command in SQL.
Read
Retrieve existing data — load your profile, show your feed. Uses the SELECT command.
Update
Modify existing data — change your name, edit a comment. Uses the UPDATE command.
Delete
Remove data — delete a message, remove an account. Uses the DELETE command.
SQL vs NoSQL
There are two main types of databases:
SQL (Relational)
Data is stored in tables with rows and columns, like a spreadsheet. Every row has the same structure. Great for complex queries, consistency, and relationships between data. Examples: MySQL, PostgreSQL.
NoSQL (Non-Relational)
Data is stored as documents (like JSON files) or key-value pairs. Flexible structure — each document can have different fields. Great for scalability, rapid development, and unstructured data. Examples: MongoDB, Firebase.
Deeper Dive
A schema defines the structure of a database — what tables exist, what columns they have, and what type of data each column can hold. SQL databases require a schema to be defined before you can add data. NoSQL databases are schemaless — you can add documents with any structure.
When the backend needs data, it sends a query. In SQL, a query looks like: SELECT name FROM users WHERE id = 1. The database engine finds the matching data and returns it, often in milliseconds even from millions of records.
Key Insight
The choice between SQL and NoSQL depends on the app. Banking apps need the strict consistency of SQL. Social media apps often prefer the flexibility and scalability of NoSQL.
Advanced
At a deeper level, databases involves rules and patterns that engineers use worldwide. Database follows standards so different brands and devices can still work together. That is why your phone, school laptop, and game console can all connect to the same network or use the same apps.
SQL does not happen in a straight line. Systems often use backup paths, error checking, and retries so information arrives correctly. When something fails, smart NoSQL helps the system recover instead of shutting down completely.
Scientists and engineers keep improving these systems every year — making them faster, safer, and more energy-efficient. The ideas you learn in this chapter are the same building blocks used in real data centers, robots, apps, and websites around the world.
Vocabulary Table
| Term | Definition |
|---|---|
| Database | An organized system for storing, managing, and retrieving data |
| SQL | Structured Query Language — used to manage relational databases with structured schemas |
| NoSQL | A type of database that stores data in flexible, non-tabular formats like documents or key-value pairs |
| Table | A collection of related data organised into rows and columns in a relational database |
| Query | A request sent to a database to retrieve or manipulate data |
| CRUD | The four basic operations: Create, Read, Update, Delete |
| Schema | The structure that defines how data is organized in a database |
Fun Facts
The term "database" was first used in the 1960s. Early databases stored data on magnetic tape — reading a record could take minutes.
MySQL is the world's most popular open-source database. It powers Facebook, Twitter, YouTube, and WordPress.
Google processes over 3.5 billion searches per day, each one querying massive distributed databases across thousands of servers.
MongoDB gets its name from the word "humongous" — it was designed to handle enormous amounts of data.
Instagram stores over 100 petabytes of data — that is 100 million gigabytes — across its SQL and NoSQL databases.
Interactive Diagram
Launch the interactive diagram to see this in action.
Open Interactive DiagramThe interactive diagram for this chapter demonstrates Databases. It shows a database visualization showing tables, records, and queries being executed.
What to explore:
- click to run a query; watch the database search tables and return results; see how data is organized in rows and columns
- databases store structured data in tables with rows and records, and use queries to efficiently retrieve and manipulate that data
Knowledge Check
1. What does CRUD stand for?
Answer: Create, Read, Update, Delete
2. Which type of database stores data in tables with rows and columns?
Answer: SQL (Relational)
3. Which of these is a NoSQL database?
Answer: MongoDB
