CRUD Operations in SQL vs MongoDB – Practice Task + Assignment for Beginners


๐Ÿงช Practice Task – CRUD Basics in SQL & MongoDB


Here's a Practice Task + Mini Assignment that complements Part 6: CRUD Operations in SQL vs NoSQL. It's designed to reinforce the differences in syntax and logic between SQL and MongoDB, while staying simple and highly practical for beginners.


๐ŸŽฏ Objective:

Perform basic Create, Read, Update, and Delete operations in both SQL and NoSQL (MongoDB).


๐Ÿ”น Scenario: School Students Data

You are managing a student database and need to do the following:

  1. Add a new student

  2. Fetch the student's data

  3. Update the student’s class

  4. Delete the student’s record


๐Ÿ“Œ A. SQL Practice

1. Create

INSERT INTO Students (StudentID, Name, Class)
VALUES (2, 'Ravi Kumar', '10B');

2. Read

SELECT * FROM Students WHERE StudentID = 2;

3. Update

UPDATE Students SET Class = '10C' WHERE StudentID = 2;

4. Delete

DELETE FROM Students WHERE StudentID = 2;

๐Ÿ“Œ B. MongoDB Practice

1. Create

db.students.insertOne({
  student_id: 2,
  name: "Ravi Kumar",
  class: "10B",
  marks: [{ subject: "English", score: 82 }]
});

2. Read

db.students.findOne({ student_id: 2 });

3. Update

db.students.updateOne(
  { student_id: 2 },
  { $set: { class: "10C" } }
);

4. Delete

db.students.deleteOne({ student_id: 2 });

๐Ÿ“ Mini Assignment: Build Your Own CRUD Set

๐Ÿ”น Instructions:

  1. Choose a student name and add them to both SQL and NoSQL.

  2. Add a subject and score for them (embedded in NoSQL).

  3. Read and display their data.

  4. Change their class and update their English score to 90.

  5. Finally, delete the record in both systems.


๐Ÿ’ก Challenge (Optional):

  • In SQL, insert marks into a separate Marks table and join it to fetch the student’s full profile.

  • In MongoDB, use $push to add a new subject to the marks array.


✅ Bonus: MongoDB $push Example

db.students.updateOne(
  { student_id: 2 },
  { $push: { marks: { subject: "Science", score: 88 } } }
);

Do you Know: The $push operator is used to add a new element to an array field in MongoDB.



Tell Us in Comments:

Which syntax do you find easier — SQL or MongoDB? Share your thoughts in the comments!

Also, Try the assignment above and share your solution in the comments.



To know about CRUD opreations read  Part 6: CRUD Operations in SQL vs NoSQL – A Beginner's Guide


✅ What’s Next?

Next: solution for the mini assignment in both SQL and NoSQL



No comments:

Post a Comment

Featured Post

CRUD Operations in SQL vs MongoDB – Practice Task + Assignment for Beginners

๐Ÿงช Practice Task – CRUD Basics in SQL & MongoDB Here's a  Practice Task + Mini Assignment  that complements  Part 6: CRUD Operations...

Popular Posts