๐ท Part 6: CRUD Operations in SQL vs NoSQL – A Beginner's Guide
This post will:
✅ Compare how to Create, Read, Update, and Delete data in both systems
✅ Use simple, realistic examples
✅ Help beginners understand key syntax differences
๐ Introduction
In any application or system that works with data, you need to perform four basic operations:
-
Create new data
-
Read existing data
-
Update current data
-
Delete data you no longer need
These are called CRUD operations — and whether you're using SQL or NoSQL, they form the core of working with databases.
Let’s explore these operations in both SQL (like MySQL/PostgreSQL) and NoSQL (like MongoDB) with clear, side-by-side examples.
๐ธ Assumed Data Structure
We’ll use a simple students
table/collection with:
-
StudentID
-
Name
-
Class
-
Marks
(embedded in NoSQL)
๐ 1. CREATE – Inserting Data
✅ SQL (MySQL/PostgreSQL)
INSERT INTO Students (StudentID, Name, Class)
VALUES (1, 'Aisha', '10A');
✅ NoSQL (MongoDB)
db.students.insertOne({
student_id: 1,
name: "Aisha",
class: "10A",
marks: [
{ subject: "Math", score: 85 }
]
});
๐ 2. READ – Retrieving Data
✅ SQL
SELECT * FROM Students WHERE StudentID = 1;
✅ NoSQL
db.students.findOne({ student_id: 1 });
๐ 3. UPDATE – Changing Data
✅ SQL
UPDATE Students
SET Class = '10B'
WHERE StudentID = 1;
✅ NoSQL
db.students.updateOne(
{ student_id: 1 },
{ $set: { class: "10B" } }
);
๐ 4. DELETE – Removing Data
✅ SQL
DELETE FROM Students
WHERE StudentID = 1;
✅ NoSQL
db.students.deleteOne({ student_id: 1 });
๐ Quick Comparison Table
Operation | SQL Syntax | MongoDB (NoSQL) Syntax |
---|---|---|
Create | INSERT INTO ... VALUES (...) |
insertOne({ ... }) |
Read | SELECT * FROM ... WHERE ... |
findOne({ ... }) |
Update | UPDATE ... SET ... WHERE ... |
updateOne({ ... }, { $set: { ... } }) |
Delete | DELETE FROM ... WHERE ... |
deleteOne({ ... }) |
๐ง Summary
SQL | NoSQL (MongoDB) |
---|---|
Structured (tables/rows) | Flexible (documents/JSON) |
Uses SQL language | Uses JavaScript-like syntax |
Schema-based | Schema-less |
Great for complex queries | Great for rapid, dynamic data |
✅ What’s Next?
In Part 7, we’ll explore Normalization vs Denormalization — how SQL and NoSQL structure data differently for performance and flexibility.