In this article, we would like to show you how to
DROP VIEW in PostgreSQL.
DROP VIEW "view_name";
To show how the
DROP VIEW statement works, we will use the following table:
At the end of this article you can find database preparation SQL queries.
In this example, we will delete the
Spain Users view which we created in this article.
DROP VIEW "Spain Users";
If you try to drop a view that already exists with
DROP VIEW query you will get an error:
If you try to
DROP VIEW IF EXISTS you will get a warning instead:
For more information go to this article: PostgreSQL - Drop view if exists
CREATE TABLE "users" ( "id" SERIAL PRIMARY KEY, "name" VARCHAR(100) NOT NULL, "email" VARCHAR(100) NOT NULL, "country" VARCHAR(15) NOT NULL );
INSERT INTO "users" ("name", "email", "country") VALUES ('Tom', 'firstname.lastname@example.org', 'Poland'), ('Chris','email@example.com', 'Spain'), ('Jack','firstname.lastname@example.org', 'Spain'), ('Kim','email@example.com', 'Vietnam'), ('Marco','firstname.lastname@example.org', 'Italy'), ('Kate','email@example.com', 'Spain'), ('Nam','firstname.lastname@example.org', 'Vietnam');