How to Delete a Row — SQL Technical Interview Questions & Answers

How to Delete a Row

How to Delete a Row

  • 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: How to Delete a Row — dELETE removes matching rows. TRUNCATE clears a whole table faster (MySQL).

Technical Interview Tip: DELETE FROM students WHERE roll = 12;

Code Examples for How to Delete a Row

How to Delete a Row — 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;

How to Delete a Row — dELETE removes matching rows. TRUNCATE clears a whole table faster (MySQL).

How to Explain How to Delete a Row 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