A View is a virtual table which is created form another table and its content are defined by a query. In real scenarios we use views for security purpose by allowing users to access data through the view, without granting the users permissions to directly access the underlying base tables.
For an illustration:
We have a customer table with the fields ('id', 'name', 'age', 'address', 'salary') but if we want to customize the perception each user has of the database and to show a table with the fields having only 'name' and 'age' then we can create view for that fields.
We are having 'CUSTOMERS' table
Now, following is the example to create a view from CUSTOMERS table.
SQL > CREATE VIEW CUSTOMERS_VIEW AS
SELECT name, age
FROM CUSTOMERS;
Now, you can query CUSTOMERS_VIEW in similar way as you query an actual table. Following is the example:
SQL > SELECT * FROM CUSTOMERS_VIEW;
This would produce the following result:
0 Comment(s)