Let’s Create Some Views
Let’s Create a view name called HighSalaryEmployees
CREATE VIEW HighSalaryEmployees
AS
SELECT * FROM EMPLOYEES;
Output:
ID | HighSalaryEmployees | GOOD_EMPLOYEE | TOP_EMPLOYEE
----|----------------------|----------------------|--------------
1 | SACHIN | Harper Lee | JOHN
2 | PRAKHAR | George Orwell | BHUVAN
3 | BADAL | F. Scott Fitzgerald | SHYAM
4 | ABHISHEK | J.D. Salinger | MADAN
5 | KARTHIK | J.R.R. Tolkien | AKASH
Let’s Create a view name called GOOD_EMPLOYEE
CREATE VIEW GOOD_EMPLOYEE AS SELECT * FROM EMPLOYEES;
Output:
ID | HighSalaryEmployees | GOOD_EMPLOYEE | TOP_EMPLOYEE
----|----------------------|----------------------|--------------
1 | SACHIN | Harper Lee | JOHN
2 | PRAKHAR | George Orwell | BHUVAN
3 | BADAL | F. Scott Fitzgerald | SHYAM
4 | ABHISHEK | J.D. Salinger | MADAN
5 | KARTHIK | J.R.R. Tolkien | AKASH
Let’s Create a view name called TOP_EMPLOYEE
CREATE VIEW TOP_EMPLOYEE AS SELECT * FROM EMPLOYEES;
Output:
ID | HighSalaryEmployees | GOOD_EMPLOYEE | TOP_EMPLOYEE
----|----------------------|----------------------|--------------
1 | SACHIN | Harper Lee | JOHN
2 | PRAKHAR | George Orwell | BHUVAN
3 | BADAL | F. Scott Fitzgerald | SHYAM
4 | ABHISHEK | J.D. Salinger | MADAN
5 | KARTHIK | J.R.R. Tolkien | AKASH
To check the Created Views:
SELECT TABLE_SCHEMA,
EMPLOYEES FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA='GFG';
To confirm that our views are created we can use the query mentioned above it will show us so our the views that we have created in form of table something like this:
TABLE_SCHEMA |
EMPLOYEES |
---|---|
GFG |
HighSalaryEmployees |
GFG |
GOOD_EMPLOYEE |
GFG |
TOP_EMPLOYEE |
SQL – DELETE View
SQL Views provide a powerful way to simplify complex queries and present data in a more understandable format. However, there may be times when we need to remove a view from your database schema. In SQL, the DELETE VIEW command does not exist. So we use the DROP VIEW command to delete a view.
In this article, We will learn about the SQL DROP VIEW with detail understanding with the help of examples and so on.