A view is simply a SQLite explanation that is put away in the data set with a related name. It is really a piece of a table as a predefined SQLite inquiry.
A view can contain all columns of a table or chose lines from at least one tables. A view can be made from one or numerous tables which relies upon the composed SQLite inquiry to make a view.
Perspectives which are somewhat virtual tables, permit the clients to −
- Construction information such that clients or classes of clients discover characteristic or natural.
- Confine admittance to the information with the end goal that a client can just see restricted information rather than a total table.
- Sum up information from different tables, which can be utilized to produce reports.
SQLite sees are perused just and in this manner you will be unable to execute a DELETE, INSERT or UPDATE proclamation on a view. Notwithstanding, you can make a trigger on a view that fires on an endeavor to DELETE, INSERT, or UPDATE a view and do what you need in the body of the trigger.
Creating Views
SQLite sees are made utilizing the CREATE VIEW articulation. SQLite perspectives can be made from a solitary table, various tables, or another view.
Following is the essential CREATE VIEW language structure.
CREATE [TEMP | TEMPORARY] VIEW view_name AS
SELECT column1, column2.....
FROM table_name
WHERE [condition];
You can remember different tables for your SELECT assertion along these lines as you use them in a typical SQL SELECT inquiry. In the event that the discretionary TEMP or TEMPORARY catchphrase is available, the view will be made in the temp information base.
Example
Consider COMPANY table with the accompanying records −
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
1 Paul 32 California 20000.0
2 Allen 25 Texas 15000.0
3 Teddy 23 Norway 20000.0
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
6 Kim 22 South-Hall 45000.0
7 James 24 Houston 10000.0
Following is a guide to make a view from COMPANY table. This view will be utilized to have a couple of sections from COMPANY table.
sqlite> CREATE VIEW COMPANY_VIEW AS
SELECT ID, NAME, AGE
FROM COMPANY;
You would now be able to question COMPANY_VIEW along these lines as you inquiry a real table. Following is a model −
sqlite> SELECT * FROM COMPANY_VIEW;
This will deliver the accompanying outcome.
ID NAME AGE
---------- ---------- ----------
1 Paul 32
2 Allen 25
3 Teddy 23
4 Mark 25
5 David 27
6 Kim 22
7 James 24
Dropping Views
To drop a view, basically utilize the DROP VIEW proclamation with the view_name. The fundamental DROP VIEW sentence structure is as per the following −
sqlite> DROP VIEW view_name;
The accompanying order will erase COMPANY_VIEW see, which we made in the last segment.
sqlite> DROP VIEW COMPANY_VIEW;
