← Lesson
BitWithBite
SQL · Quick Reference

Lesson 4 — INSERT, UPDATE & DELETE Cheat Sheet

SQL

Key Ideas

1INSERT INTO. SQL -- Insert single row INSERT INTO students (name, age, grade) VALUES ( 'Zara Malik' , 17 , 'A' ); -- Insert multiple rows (more efficient — one transaction) INSERT ...
2UPDATE — Always Use WHERE. SQL -- ALWAYS use WHERE with UPDATE! UPDATE students SET grade = 'A+' WHERE id = 3 ; -- Update multiple columns UPDATE students SET grade = 'A' , email = 'newemail@tes...
3DELETE. SQL -- Delete a specific row (WHERE is critical!) DELETE FROM students WHERE id = 5 ; -- Delete multiple rows DELETE FROM students WHERE grade = 'F' ; -- TRUNCATE remo...
4Safe DML with Transactions. SQL -- Safe update pattern START TRANSACTION ; UPDATE students SET grade = 'A+' WHERE id = 10 ; -- Check the result before committing SELECT * FROM students WHERE id =...
5ON DUPLICATE KEY UPDATE (Upsert). SQL -- Insert or update if duplicate key exists INSERT INTO students (id, name, grade) VALUES ( 1 , 'Sara Ahmed' , 'A+' ) ON DUPLICATE KEY UPDATE grade = 'A+' ; -- REP...

Code Examples

-- Insert single row INSERT INTO students (name, age, grade) VALUES ('Zara Malik', 17, 'A'); -- Insert multiple rows (more efficient — one transaction) INSERT INTO students (name, age, grade) VALUES ('Hassan Ali', 16, 'B'), ('Nadia Khan', 18...
-- ALWAYS use WHERE with UPDATE! UPDATE students SET grade = 'A+' WHERE id = 3; -- Update multiple columns UPDATE students SET grade = 'A', email = 'newemail@test.com' WHERE name = 'Hassan Ali'; -- Update with calculation UPDATE products SET p...
-- Delete a specific row (WHERE is critical!) DELETE FROM students WHERE id = 5; -- Delete multiple rows DELETE FROM students WHERE grade = 'F'; -- TRUNCATE removes ALL rows (faster, resets AUTO_INCREMENT) TRUNCATE TABLE temp_logs; -- DELETE vs ...