Introduction to Databases
Table of Contents + −
Think about any app you use. Like Instagram, or your bank app, or Amazon. Here’s a question:
- You log in today and your posts, your friends, your orders are all still there.
- You close the app, switch off your phone, come back next week, and it’s all still there.
- So where exactly is all that stuff being kept while the app is closed?
The short answer is a database. Every serious app has one sitting behind it, quietly holding all the important data. So let’s understand what that really means.
🎯 The Problem
Before we talk about databases, let’s see why we even need them. Imagine you’re building a small app and you decide to just store data yourself. You’d quickly hit walls:
- Memory forgets. If you keep data only in your program’s memory, it vanishes the moment the app closes or the server restarts. Your users would lose everything every time.
- Plain files get messy. Okay, so you save to a text file instead. That works for ten users. But what about finding one specific user out of a million? You’d have to read the whole file top to bottom every single time.
- Many people at once. Now two users try to update the same file at the same moment. They overwrite each other, and data gets corrupted.
- No safety rules. Nothing stops you from saving a user with no email, or two users with the same ID. The data slowly turns into garbage.
So storing data the naive way falls apart fast. You need something built for this job. That something is a database.
🗄️ What is a Database
Let’s define it plainly.
- A database is an organized store of data that you can save into, find things in, update, and delete from. That’s the whole idea.
- The four basic things you do with data have a nickname: CRUD. It stands for Create, Read, Update, Delete. Create means add new data, Read means find it, Update means change it, Delete means remove it.
Now you don’t talk to the raw data directly. There’s a piece of software in the middle that manages everything for you.
- That software is called a DBMS, which stands for Database Management System.
- The DBMS is the program that actually stores the data, keeps it safe, and answers your questions about it. When people say “MySQL” or “MongoDB”, they’re naming the DBMS.
So when we loosely say “the database”, we usually mean the DBMS plus the data it’s looking after.
🧩 What Databases Give You
So why use a database instead of a file? Because a database hands you a bunch of hard problems already solved:
- Persistence. Your data stays around even after the app closes or the server restarts. It’s saved to disk, not just held in memory.
- Fast search. A database can find one record out of millions in a blink, because it keeps smart indexes instead of reading everything top to bottom.
- Many users at once. Lots of people can read and write at the same time without stepping on each other. The database sorts out the order safely.
- Integrity. You can set rules, like “every user must have a unique email”, and the database enforces them so bad data can’t sneak in.
That last one matters a lot. Integrity just means the data stays correct and trustworthy.
🔤 Talking to a Database
So how do you actually ask a database for something? You send it a query.
- A query is just a request you send to the database. Like “give me all users from India” or “add this new order”.
- For most relational databases, you write queries in a language called SQL. SQL stands for Structured Query Language, and it’s basically a clear, English-like way to ask the database for exactly what you want.
Here’s a tiny query that says “find the name and email of the user whose id is 42”.
SELECT name, emailFROM usersWHERE id = 42;Let’s read it line by line:
SELECT name, emailsays which columns you want back, here just the name and email.FROM userssays where to look, theuserstable.WHERE id = 42is the filter, only the row whose id is 42.
So in plain words, this query says: “Look in the users table, find the one with id 42, and give me their name and email.” That’s it. The database does the searching for you.
🌳 Main Types
Databases come in a few flavors, but at a high level you’ll mostly meet two big families.
- Relational databases, also called SQL databases, store data in tables made of rows and columns, kind of like a set of connected spreadsheets. Each row is one record, like one user, and the columns are its fields, like name and email. Examples are MySQL and PostgreSQL.
- NoSQL databases store data in more flexible shapes, like documents or key-value pairs, instead of strict tables. They’re handy when your data doesn’t fit neatly into rows and columns, or when you need to scale to huge size. Examples are MongoDB and Redis.
Here’s a quick side-by-side to keep them straight.
| Aspect | Relational (SQL) | NoSQL |
|---|---|---|
| How data is stored | Tables with rows and columns | Documents, key-value, and more |
| Structure | Fixed schema, set in advance | Flexible, can vary per record |
| Query language | SQL | Varies by database |
| Examples | MySQL, PostgreSQL | MongoDB, Redis |
| Best for | Structured, related data | Flexible or very large-scale data |
Don’t worry about picking a side yet. We’ll dig into each one properly in the next lessons.
🏗️ Where the Database Fits
So where does the database actually sit in a real app? It’s not the part you click. It lives in the back, behind the server.
- You tap something in the app, which is the frontend, the part you see and touch.
- That goes to the app server, the program that handles the request and holds the logic.
- The app server talks to the database to read or write data, then sends the answer back to you.
So you never talk to the database directly. The app server is the middleman that does the reading and writing for you.
When you post a photo, the app server takes it and writes it into the database. When you open your feed, the app server reads it back out. Same database, two directions.
⚠️ Common Mistakes and Misconceptions
A few ideas trip people up early. Let’s clear them out:
- “A database is just a fancy spreadsheet.” They look similar, sure. But a database handles millions of records, many users at once, safety rules, and lightning-fast search. A spreadsheet crashes at all of those.
- “One type fits everything.” Nope. Relational and NoSQL each shine in different situations. Picking the right one for the job is a real skill, and there’s no single winner.
- “I’ll just keep data in the app’s memory.” Tempting, but memory clears the moment the app or server stops. Anything you want to keep around has to go into a real database that saves to disk.
🧩 What You’ve Learned
You can now explain what a database is and why every app needs one. Here’s what you’ve picked up.
- ✅ A database is an organized store of data you can create, read, update, and delete.
- ✅ A DBMS is the software that manages the data and answers your queries.
- ✅ Databases give you persistence, fast search, many users at once, and data integrity.
- ✅ You talk to a database with queries, and SQL is the common query language.
- ✅ The two main families are relational (SQL) and NoSQL, each good for different jobs.
- ✅ The database sits behind the app server, which reads and writes data for you.
Check Your Knowledge
Test what you learned. Pick an answer for each question, then click Check.
- 1
What is a DBMS?
Why: A DBMS (Database Management System) is the software, like MySQL or MongoDB, that stores the data and answers your queries.
- 2
What do the four letters in CRUD stand for?
Why: CRUD is the four basic operations on data: Create, Read, Update, and Delete.
- 3
Why is a plain file a poor choice for storing app data at scale?
Why: A plain file struggles with fast search, many users writing at once, and enforcing rules, which is exactly what a database solves.
- 4
How does a relational (SQL) database store its data?
Why: Relational databases store data in tables of rows and columns following a fixed schema, while NoSQL databases use more flexible shapes.
🚀 What’s Next?
You’ve got the big picture. Next, we’ll go deeper into the two families and how to choose between them.
- SQL vs NoSQL breaks down when to reach for each type, with real trade-offs.
- Relational Databases takes a closer look at tables, rows, keys, and how data connects.
Once you’ve got those, you’ll be ready to design the data layer of a real system with confidence.