✏️ Explanatory Question

What are the basic CRUD operations in MySQL?

👁 7 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

Section 3: CRUD & Basic Queries

19

What are the basic CRUD operations in MySQL?

Level: Basic — The foundation of all database work; every developer must know these cold.

CRUD stands for the four fundamental operations you can perform on data in any database: Create, Read, Update, and Delete. Each maps to a specific SQL command.

The Four CRUD Operations

  • Create → INSERT: Adds new rows to a table.
  • Read → SELECT: Retrieves/queries existing data.
  • Update → UPDATE: Modifies existing rows.
  • Delete → DELETE: Removes rows from a table.
Critical safety tip: Always use a WHERE clause with UPDATE and DELETE. Forgetting it will modify or delete every row in the table!

CRUD Mapping

Operation SQL Command SQL Category Purpose
Create INSERT DML Add new records
Read SELECT DQL Fetch records
Update UPDATE DML Modify records
Delete DELETE DML Remove records

Quick Example — All Four Operations

-- Setup a sample table
CREATE TABLE students (
    id    INT AUTO_INCREMENT PRIMARY KEY,
    name  VARCHAR(50),
    marks INT
);

-- CREATE: insert new rows
INSERT INTO students (name, marks) VALUES ('Rumman', 85);
INSERT INTO students (name, marks) VALUES ('Ansari', 90);

-- READ: fetch data
SELECT * FROM students;
SELECT name FROM students WHERE marks > 80;

-- UPDATE: modify a row (WHERE is essential!)
UPDATE students SET marks = 95 WHERE id = 1;

-- DELETE: remove a row (WHERE is essential!)
DELETE FROM students WHERE id = 2;
Interviewer tip: The one-liner they want — "CRUD represents the four basic database operations — Create (INSERT), Read (SELECT), Update (UPDATE), and Delete (DELETE) — that form the foundation of data manipulation."