Rename Table — SQL Technical Interview Questions & Answers
Rename Table
Rename Table
- RENAME TABLE students TO learners; or ALTER TABLE students RENAME TO learners; Both change the table name. Apps and FOREIGN KEYs that still say students will break until you update them.
- Trap: renaming in production during peak hours without updating the app.
- On the example next to this theory: Rename Table: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Technical Interview Tip: RENAME TABLE students TO learners;
Code Examples for Rename Table
Rename Table — sample query
-- Rename 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;Rename Table: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
How to Explain Rename Table to an Interviewer
How do you rename a table?
RENAME TABLE old TO new; or ALTER TABLE … RENAME TO