Google News
logo
PostgreSQL - Interview Questions
What Is a SQL View?
A view is a database object that acts as a temporary or virtual table. You can query it like a regular table. It can be used in the FROM clause of a SELECT, and you can reference view columns in SELECT, WHERE, GROUP BY, and other clauses.
 
Views and tables differ in some important ways:
 
* Views do not store any records anywhere.
* Tables store records physically, on a disk.
* Views use existing records; they can also calculate new records as needed.

Views are useful for summarizing the data from single or multiple tables. They also provide an additional layer of data security. For example, you can create a view and only give the relevant users access to that view.
 
A simple example of a view might look like this :
 
CREATE VIEW european_customers AS
SELECT customer_id, customer_name
FROM customers
WHERE region = 'Europe';
 
To use this view, you’d write:
SELECT *
FROM european_customers;
Advertisement