Day 31 of #100DaysOfCode — SQL + NoSQL Basics

Published: (March 4, 2026 at 07:09 PM EST)
4 min read
Source: Dev.to

Source: Dev.to

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:

idnameemail
1Johnjohn@gmail.com
2Saadsaad@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);

Read 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 `, `<`, `IN`, `LIKE`.*

Update a document

db.users.updateOne(
  { email: "alice@email.com" },
  { $set: { age: 29 } }
);

Delete documents

db.users.deleteMany({ age: { $lt: 18 } });

Join collections (aggregation with $lookup)

db.orders.aggregate([
  {
    $lookup: {
      from: "users",
      localField: "user_id",
      foreignField: "_id",
      as: "user"
    }
  },
  { $unwind: "$user" }
]);

Aggregation pipeline example

db.users.aggregate([
  { $match: { age: { $gt: 20 } } },
  { $group: { _id: "$age", count: { $sum: 1 } } },
  { $sort: { count: -1 } }
]);

🔵 Use Cases for NoSQL / Document Databases

Document databases and NoSQL excel wherever data is fluid, scale is massive, speed is critical, or the structure of each record genuinely varies. Typical real‑world scenarios include:

  • 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?

Why SQL Wins

ScenarioReason
Structured, relational dataTables with clear relationships (users → orders → products)
Data integrity is criticalACID transactions, foreign keys, constraints
Complex queriesJOINs, aggregations, reporting, analytics
Schema is stableData shape doesn’t change often

Why NoSQL Wins

ScenarioReason
Highly variable or evolving schemaSchemaless collections allow fields to differ per document
Massive horizontal scalingSharding and distributed architecture built‑in
Fast read/write for simple queriesDenormalized data eliminates costly joins
Unstructured or semi‑structured dataJSON‑like documents map naturally to many modern data formats

Both paradigms have their strengths; the right choice depends on the specific requirements of your application.

Financial/Transactional Systems

Banks, ERP, e‑commerce backends

When to Use NoSQL

ScenarioReason
Flexible/evolving schemaFields vary per record; schema changes frequently
Massive scale & speedHorizontal scaling across many servers
Unstructured / semi‑structured dataJSON documents, logs, sensor data
High write throughputMillions of events/second (Cassandra, DynamoDB)
Hierarchical or graph dataNested docs (MongoDB), relationships (Neo4j)
CachingKey‑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.
  • 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!

0 views
Back to Blog

Related posts

Read more »