What is a Database?
After completing this topic
You will be able to explain why databases are needed, understand the meaning of CRUD, and know the difference between SQL and NoSQL.
Why Files Are Not Enough
If a program needs to store data, the simplest method is to use a file. For example, you can store a list of users in a JSON file.
[
{"id": 1, "name": "Kim Hun", "email": "hoon@example.com"},
{"id": 2, "name": "Lee Soo", "email": "su@example.com"}
]This method is fine at first, but soon problems arise:
- If there are 10,000 users, searching becomes slowβbecause you have to read the entire file.
- If two people modify it at the same time, the data is overwritten.
- For complex queries like "Find users with the email 'naver.com'," you have to write code yourself.
A database (DB) is a specialized data storage and retrieval system created to solve these problems.
CRUD β The Four Operations on Data
In a database, there are ultimately four operations:
| Operation | Meaning | SQL Keyword |
|---|---|---|
| Create | Create new data | INSERT |
| Read | Read/search data | SELECT |
| Update | Modify existing data | UPDATE |
| Delete | Delete data | DELETE |
Almost all functions of a web application are a combination of CRUD. Sign-up (C), list of posts (R), profile modification (U), account deletion (D).
Relational Databases β Organized into Tables
The oldest and most widely used method is the relational database (RDBMS). Data is stored in a table format.
users table:
+----+--------+---------------------+
| id | name | email |
+----+--------+---------------------+
| 1 | Kim Hun | hoon@example.com |
| 2 | Lee Soo | su@example.com |
+----+--------+---------------------+Each row is a piece of data, and each column is an attribute. The language used to query this table is SQL.
-- Find users with the email naver.com
SELECT name, email FROM users WHERE email LIKE '%@naver.com';Representative RDBMS: MySQL, PostgreSQL, SQLite, Oracle.
NoSQL β Databases That Are Not Table-Based
Not all data fits neatly into a table. If users have different attributes or the data structure changes frequently, NoSQL is used.
// MongoDB document example
{
"_id": "abc123",
"name": "Kim Hun",
"skills": ["Python", "JavaScript"],
"address": {
"city": "Seoul",
"district": "Gangnam"
}
}It stores data in a JSON-like structure without SQL. It is flexible, but complex relationships (JOINs) are inconvenient.
Representative NoSQL: MongoDB, Redis, Firebase, Supabase (PostgreSQL-based but a BaaS).
What Should You Learn?
| Situation | Recommendation |
|---|---|
| Web development basics | MySQL or PostgreSQL (SQL required) |
| Rapid prototyping | Supabase, Firebase (minimal setup) |
| Large-scale unstructured data | MongoDB |
It is best to learn SQL first. SQL is fundamental no matter what database you use, and it trains you in the very act of dealing with data.
β Apply to your bio: DevBench β Database Basics