Temporary Table — SQL Technical Interview Questions & Answers
Temporary Table
Temporary Table
- CREATE TEMPORARY TABLE tmp_fail AS SELECT * FROM students WHERE marks < 40; lives only for this connection. When you disconnect, it disappears. Other users cannot see it.
- Use it for a messy report: filter, join, then SELECT from tmp. Don’t confuse with a normal table of the same name — TEMPORARY hides the real one in that session.
- Trap: expecting a temporary table to still be there tomorrow.
- On the example next to this theory: Temporary Table: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Technical Interview Tip: CREATE TEMPORARY TABLE … — gone when the session ends.
Code Examples for Temporary Table
Temporary Table — sample query
-- Temporary 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;Temporary Table: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
How to Explain Temporary Table to an Interviewer
Who can see a TEMPORARY table?
Only this connection Dropped on disconnect