CREATE VIEW
The view is a virtual table in PostgreSQL that does not store any data, since it has no physical existence as such.
Syntax:
CREATE [TEMP | TEMPORARY] VIEW name AS SELECT column_1, column_2, column_3,...... FROM table WHERE view_conditions;
Parameters:
name: It is used to specify the name of the PostgreSQL VIEW to be created.
Example:
CREATE VIEW stud AS
SELECT “STUDENT_ID”, “STUDENT_AGE”
FROM “STUDENTS” ; |
Output:
Query returned successfully with no result in 30 msec.
Explanation:
The above query is executed to create a view called stud. In order to check the PostgreSQL VIEW, another query needs to be executed.
Output:
STUDENT_ID | STUDENT_AGE |
1 | 10 |
2 | 13 |
3 | 11 |
4 | 13 |
5 | 10 |
PostgreSQL DROP VIEW
To entirely remove or delete a PostgreSQL VIEW, the DROP VIEW statement is used.
Syntax:
DROP VIEW [IF EXISTS] name;
Parameters:
name: It is used to specify the name of the PostgreSQL VIEW to be deleted.
Example:
DROP VIEW stud; |
Explanation:
In the above example, we are deleting or removing the PostgreSQL VIEW stud. After the execution, the PostgreSQL VIEW stud, will be completely deleted, if it exists, otherwise an error will be displayed.
Drop View using UI:
- Right-click on the selected view.
- Click on Delete/Drop option.
- Click on the “Yes” button from the pop-up generated.
- The View is thus dropped permanently.