SQL Interview — SQL Technical Interview Questions & Answers
SQL Interview
SQL Interview
- A view is a saved SELECT with a name. CREATE VIEW fail_list AS SELECT name, marks FROM students WHERE marks < 40; Then SELECT * FROM fail_list; looks like a table but it runs that query each time (simple views).
- Teachers like views for ‘show only what this role should see’. You don’t copy data. If students.marks changes, fail_list changes.
- Some views are not updatable (JOIN, GROUP BY). INSERT into fail_list may fail. Don’t promise ‘views always write back’.
- Trap: thinking a view stores a snapshot forever. Unless you made a table, it is a query with a nickname.
- On the example next to this theory: Interview: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
- On the example next to this theory: SQL Interview: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
Technical Interview Tip: CREATE VIEW fail_list AS SELECT … WHERE marks < 40;
Code Examples for SQL Interview
SQL Interview — sample query
-- SQL Interview
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;SQL Interview: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.
How to Explain SQL Interview to an Interviewer
What is a view?
A saved SELECT with a name Not a second copy of the data
Can you always UPDATE a view?
No JOINs / GROUP BY often block it