CodesJava

Easy learning with example program codes

VIEW in PostgreSQL

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	12
3	15
4	9

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:

  1. Right-click on the selected view.
  2. Click on Delete/Drop option.
  3. Click on the “Yes” button from the pop-up generated.
  4. The View is thus dropped permanently.
Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status