In SQL, a View is a virtual table that is generated based on a SQL statement. It has no own data, but it returns data from others table. This article describes about SQL views or creation of SQL views. Summary of the article:
- What is SQL View?
- How to create SQL View?
- How to Drop SQL View?
- How to use View?
What is SQL View?
SQL View is a virtual table. It has no physical existence and is created by SQL query joining tables. Every view contains rows and columns as like a real table. But it does not contain actual data like real table. A view can be built on a single table or multiple tables. It can build on another view. Views display only those data which are defined in the query.
We can use SQL functions, WHERE, and JOIN statements with a view.
How to create SQL View?
Views are created using the CREATE VIEW statement. To create a view, a user must have the appropriate system privilege according to the specific implementation. The basic CREATE VIEW syntax is as follows:
CREATE VIEW ViewName AS
How to Drop SQL View?
We can drop a view using the following command.
DROP VIEW ViewName;
How to use View?
A View provides lot of advantages. The advantages of views are given bellow:
- It is easy to use.
- It saves space. Because it takes very little space to store and do not store the actual data.
- It provides better data security. Because it only returns the selected data to the end user.
- It provides code security. That means we can encrypt a view.
The View is an important feature of relational database. For better performance and security related issues we can easily use view.