✏️ Explanatory Question
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.
WHERE clause with UPDATE and DELETE. Forgetting it will modify or delete every row in the table!
| 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 |
-- 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;