SQL Views
You need to contact your DBA to check if you have access to create views for yourself. A view is a virtual table that has fields and data from some SQL table.
Create a view
Syntax:
CREATE VIEW view_name AS
SELECT column_name1, column_name2,....
FROM table_name
WHERE condition;
Consider the table,
marks_maria, given below:
| Subject |
I term |
II term |
III term |
IV term |
| Maths |
90 |
78 |
75 |
80 |
| English |
72 |
68 |
76 |
62 |
| French |
78 |
75 |
63 |
58 |
| Science |
93 |
88 |
84 |
75 |
Suppose, we need to create a view which has Ist and IInd terms marks of French and Science. The SQL statement is given below:
CREATE VIEW marks AS
SELECT Subject, I term, II term
FROM marks_maria
WHERE Subject='French' OR Subject='Science';
The view named,
marks will be created.
Query a view
A view can be queried just like a simple database. Suppose, we want to view the view above. We can view this view by the following SQL:
SELECT * FROM marks;
The view will be as follows:
| Subject |
I term |
II term |
| French |
78 |
75 |
| Science |
93 |
88 |
Delete a view
To delete a view, the syntax is:
DROP VIEW view_name;
The
marks view can be deleted by the following SQL query:
DROP VIEW marks;