QA
Beginner LevelSQL & MySQL

What are SQL Views and when should you use CREATE VIEW?

❓ Interview Prompt: Explain SQL Views, `CREATE VIEW`, virtual tables, query simplification, security abstraction, and performance considerations.

A SQL View is a virtual table defined by a saved SQL query. Views do not store data physically on disk (unlike tables); they execute their underlying query whenever referenced:

Benefits:

1
Query Simplification: Encapsulates complex joins and aggregations into a simple virtual table.
2
Security & Abstraction: Restricts user access to specific rows and columns while hiding sensitive base tables.

Code Implementation Example

sql
CREATE VIEW v_active_customer_orders AS
SELECT 
    u.id AS user_id,
    u.email,
    COUNT(o.id) AS total_orders,
    SUM(o.total_amount) AS total_spent
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE u.status = 'ACTIVE'
GROUP BY u.id, u.email;
💡Creating a virtual view summarizing active customer order histories.
🎯 Interview Key Takeaway

Use Views to simplify complex multi-table joins and encapsulate data access permissions cleanly.

#SQL#Views#CREATE VIEW#Abstraction#Beginner
Back to all SQL & MySQL Questions→

More SQL & MySQL Interview Questions

Beginner LevelSQL & MySQL

How do B-Tree Indexes work in SQL/MySQL and how do you optimize slow queries using EXPLAIN?

Beginner LevelSQL & MySQL

How do SELECT, WHERE, ORDER BY, and LIMIT clauses filter relational datasets?

Beginner LevelSQL & MySQL

What are INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN?