DELETE Record — SQL Technical Interview Questions & Answers
DELETE Record
DELETE Record
- DELETE FROM students WHERE roll = 12; removes matching rows. The table remains. DELETE FROM students; with no WHERE deletes everyone — same danger as UPDATE.
- FOREIGN KEY: you cannot delete Asha if marks rows still point to her roll, unless ON DELETE CASCADE. That is a feature. Don’t disable FK to ‘make DELETE work’ in production.
- Trap: DELETE vs DROP vs TRUNCATE mixed up. DELETE = rows. TRUNCATE = all rows, keep table. DROP = table gone.
- On the example next to this theory: DELETE Record — dELETE removes matching rows. TRUNCATE clears a whole table faster (MySQL).
Technical Interview Tip: DELETE FROM students WHERE roll = 12;
Code Examples for DELETE Record
DELETE Record — sample query
CREATE TABLE tags (id INTEGER PRIMARY KEY, label TEXT);
INSERT INTO tags VALUES (1, 'old'), (2, 'keep');
DELETE FROM tags WHERE label = 'old';
SELECT * FROM tags;DELETE Record — dELETE removes matching rows. TRUNCATE clears a whole table faster (MySQL).
How to Explain DELETE Record to an Interviewer
Write a DELETE.
DELETE FROM students WHERE roll = 12;
DELETE vs TRUNCATE vs DROP?
DELETE rows TRUNCATE all rows keep table DROP table