There are two methods for organizing a database: a structured approach using tables and rows, and an unstructured approach using collections and documents. The structured method employs SQL (Structured Query Language), whereas the unstructured method is known as NoSQL (Not Only SQL).
On Day 31, I explored both methods for writing a database, understood the differences between them, and identified the use cases for each.
Structured way (Tables and Rows)
It is what is called a Relational Database — a way of organizing data into tables, where:
- Table → represents one entity (e.g., Users, Orders)
- Row → one record/entry in that table (e.g., one user)
- Column → an attribute/field (e.g. name, email, age)
- Cell → the actual value where a row and column intersect
It looks exactly like a spreadsheet:
| id | name | |
|---|---|---|
| 1 | John | john@gmail.com |
| 2 | Saad | saad@gmail.com |
🔑 Key Concepts
- Schema — the overall structure/blueprint of all your tables
- Primary Key — a unique identifier for each row
- Foreign Key — a column that links one table to another
- Relationship — how tables are connected
🟦 SQL Basic Syntax
Create a table
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
email VARCHAR(255) UNIQUE,
age INT
);
Insert Rows
INSERT INTO users (name, email, age)
VALUES ('Alice', 'alice@email.com', 28);
Reading Data
SELECT name, email FROM users WHERE age > 25 ORDER BY name ASC LIMIT 10;
Update a Row
UPDATE users SET age = 29 WHERE email = 'alice@email.com';
Delete a Row
DELETE FROM users WHERE age < 18;
Join a table
SELECT users.name, orders.product
FROM users
INNER JOIN orders ON users.id = orders.user_id;
🟦 SQL Use Cases
Relational databases and SQL shine in any domain where data has a clear structure, relationships between entities matter, and consistency is non-negotiable. Here are the most important real-world use cases:
- Banking & Financial Systems
- E-commerce Platforms
- Healthcare & Electronic Medical Records
- HR & Payroll Systems
- Inventory Management
- Government & Legal Databases
- School & University Systems
- Reservation & Booking Systems
🟧 Unstructured Databases (NoSQL): Collections & Documents
It is what is called a Document Database — a way of organizing data in the form of documents and collections, where:
- Collection = a group of related documents (similar to a table)
- Document = a single record (similar to a row)
- Field = a key-value pair (similar to a column)
🟧 NoSQL Basic Syntax
Insert a Document
(Collection auto-creates — no schema required.)
db.users.insertOne({ name: "Alice", email: "alice@email.com", age: 28 });
Insert Many Documents
db.users.insertMany([
{ name: "Bob", age: 32 },
{ name: "Carol", age: 25, role: "admin" } // different fields — totally fine
]);
Read Documents
db.users.find({ age: { $gt: 25 } }, { name: 1, email: 1 });
-- Operators like `$gt`, `$lt`, `$in`, `$regex` replace SQL's `>`, `<`, `IN`, `LIKE`.
Update a Document
db.users.updateOne({ email: "alice@email.com" }, { $set: { age: 29 } });
Delete Documents
db.users.deleteMany({ age: { $lt: 18 } });
Use case
Document databases and NoSQL excel wherever data is fluid, scale is massive, speed is critical, or the structure of each record genuinely varies. Here are the most important real-world use cases:
- Content Management & Blogging Platforms
- Social Media Feeds & User Profiles
- Real-time Chat & Messaging
- Product Catalogs
- Mobile & Gaming Apps
- User Activity & Behavioral Analytics
- IoT & Sensor Data
- Recommendation Engines
- Logistics & Delivery Tracking
- Rapid Prototyping & Startups
🔵 SQL vs 🟠 NoSQL: When to Use Which?
Use SQL when...
| Scenario | Why SQL wins |
|---|---|
| Structured, relational data | Tables with clear relationships (users → orders → products) |
| Data integrity is critical | ACID transactions, foreign keys, constraints |
| Complex queries | JOINs, aggregations, reporting, analytics |
| Schema is stable | Data shape doesn't change often |
| Financial/transactional systems | Banks, ERP, e-commerce backends |
Use NoSQL when...
| Scenario | Why NoSQL wins |
|---|---|
| Flexible/evolving schema | Fields vary per record, schema changes frequently |
| Massive scale & speed | Horizontal scaling across many servers |
| Unstructured/semi-structured data | JSON documents, logs, sensor data |
| High write throughput | Millions of events/sec (Cassandra, DynamoDB) |
| Hierarchical or graph data | Nested docs (MongoDB), relationships (Neo4j) |
| Caching | Key-value stores like Redis |
🧭 Quick Decision Guide
Is the data relational with a stable schema? → SQL
Need ACID compliance (finance, healthcare)? → SQL
Unknown/flexible data structure? → NoSQL (Document)
Massive scale, simple lookups? → NoSQL (Key-Value)
Graph relationships (social networks)? → NoSQL (Graph)
Time-series or IoT data? → NoSQL (Wide-Column)
✅ Conclusion
Day 31 gave me a clear picture of how SQL and NoSQL differ—not just syntactically, but philosophically. SQL focuses on structure, rules, and consistency, while NoSQL prioritizes flexibility, speed, and scalability. Understanding when to choose each one is a core skill for backend developers, and this comparison helped solidify that understanding. Tomorrow, I’ll build on this foundation as I continue my #100DaysOfCode journey.
Thanks for reading. Feel free to share your thoughts!
Top comments (0)