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...