Storage Engines — SQL Technical Interview Questions & Answers

Storage Engines

Storage Engines

  • A storage engine is how the table is stored. SHOW ENGINES; InnoDB is default (transactions, FKs). MyISAM: old, table locks. MEMORY: RAM, lost on restart. CSV: CSV files, little use in apps.
  • CREATE TABLE … ENGINE=InnoDB; Usually omit it and take the default.
  • Trap: MEMORY for data you cannot lose. Trap: mixing engines then expecting FKs between them.
  • On the example next to this theory: Storage Engines: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Technical Interview Tip: InnoDB default. SHOW ENGINES; to list.

Code Examples for Storage Engines

Storage Engines — sample query

-- Storage Engines
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;

Storage Engines: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

How to Explain Storage Engines to an Interviewer

Default engine?

InnoDB