Skip to content
We areTOP 1%

What is a view, and how is it different from a table?

EasyConceptDBMS Fundamentals
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews

Answer

A view is a virtual table defined by a stored SELECT query. A normal view holds no data of its own: each time you query it, the database runs its query against the base tables, so the view always shows current data. A table, in contrast, physically stores its rows.

  • Views simplify complex queries: a long join is written once and then used like a table.
  • Views improve security: a user can be given access to a view that shows only some columns or rows.
  • A simple view on one table can usually be updated, but views with joins, GROUP BY or DISTINCT are generally read-only.
  • A materialized view (PostgreSQL, Oracle) stores the result physically and must be refreshed, trading freshness for speed. MySQL has no materialized views.

Example:

CREATE VIEW cse_students AS
SELECT roll, name FROM students WHERE dept = 'CSE';

SELECT * FROM cse_students;   -- runs the stored query

Users of the view never see the phone or marks columns of students.

More in DBMS Fundamentals

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account