Repair Table — SQL Technical Interview Questions & Answers
Repair Table
Repair Table
- REPAIR TABLE is mainly for MyISAM tables that got corrupted. InnoDB almost never wants REPAIR TABLE — you use dump/restore or innodb recovery settings instead.
- If a teacher’s old lab uses MyISAM and SELECT crashes, they may show REPAIR TABLE t; Don’t make it your default InnoDB answer.
- Trap: REPAIR TABLE on InnoDB and thinking it ‘optimises’ like OPTIMIZE TABLE.
- On the example next to this theory: Repair Table: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Technical Interview Tip: MyISAM: REPAIR TABLE. InnoDB: don’t; restore from backup.
Code Examples for Repair Table
Repair Table — sample query
-- Repair Table
CREATE TABLE demo (
id INTEGER PRIMARY KEY,
label TEXT NOT NULL,
qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
(1, 'alpha', 2),
(2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;Repair Table: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
How to Explain Repair Table to an Interviewer
When is REPAIR TABLE used?
MyISAM corruption Not the InnoDB everyday tool