Table vs View — SQL Technical Interview Questions & Answers
Table vs View
Table vs View
- A table stores rows on disk. A view stores a query. SELECT from both looks similar. INSERT goes to a table (and only some views). Indexes live on tables. DROP TABLE destroys data. DROP VIEW destroys the saved query, not the base data.
- Trap: ‘view is a virtual table’ without saying the data still lives in base tables.
- On the example next to this theory: Table vs View — a view is a stored SELECT you can query like a table.
Technical Interview Tip: Table holds data. View holds a query.
Code Examples for Table vs View
Table vs View — sample query
CREATE TABLE employees (id INTEGER PRIMARY KEY, name TEXT, salary INTEGER);
INSERT INTO employees VALUES (1, 'Asha', 70000), (2, 'Ravi', 50000);
CREATE VIEW high_pay AS
SELECT name, salary FROM employees WHERE salary >= 60000;
SELECT * FROM high_pay;Table vs View — a view is a stored SELECT you can query like a table.
How to Explain Table vs View to an Interviewer
Does DROP VIEW delete data?
No Base tables still have the rows