Views serve as an important tool for simplifying complex queries, enhancing data security, and streamlining database management. They provide a virtual layer that presents data from underlying tables in a structured format. However, views like other database objects need to be managed effectively to maintain data integrity and optimize performance
In this article, We will learn about the PL/SQL DROP VIEW by understanding the various examples with the output in detail.
PL/SQL DROP VIEW
PL/SQL
DROP VIEW
is a statement used to remove a view from the database.
- When we drop a view, the view definition is removed from the database schema and the view can no longer be accessed or used in queries.
Syntax for Drop a View in PL/SQL:
DROP VIEW view_name;
Explanation:
- DROP VIEW statement is used to delete the view from the database. It is a Data Definition Language (DDL) statement.
- view_name is specified as the name of the view that you want to be deleted. Once we execute the DROP VIEW statement along with the name of the view you want to remove the view, the database system will delete the view and its definition from the database.
Consider a Table
To understand the PL/SQL DROP VIEW we need a table on which we will perform various operations and queries. Here we will consider a table called products which is shown below:
product_id
| product_name
| price
| stock_quantity
|
---|
1
| Laptop
| 12000
| 50
|
2
| Mobilephone
| 11500
| 52
|
3
| Headset
| 750
| 85
|
4
| Pens
| 100
| 25
|
Let's Create Some View
Let's Create a view named `products_list` that includes `product_id`, `product_name`, and `price` from the `products` table, and then select all data from this view.
CREATE OR REPLACE VIEW products_list AS
SELECT product_id, product_name, price
FROM
products;
select * from products_list;
Output:
product_id
| product_name
| price
|
---|
1
| Laptop
| 12000
|
2
| Mobilephone
| 11500
|
3
| Headset
| 750
|
4
| pens
| 100
|
Explanation:The above output shows the details of products_list view.
Let's Create another view named `expensive_products` that includes `product_id`, `product_name`, and `price` from the `products` table where the `price` is greater than 1000, and then select all data from this view.
CREATE OR REPLACE VIEW expensive_products AS
SELECT product_id, product_name, price
FROM
products
WHERE price > 1000;
select * from expensive_products;
Output:
product_id
| product_name
| price
|
---|
1
| Laptop
| 12000
|
2
| Mobilephone
| 11500
|
Explanation:The above output shows the items which price is more than 1000.
Let's DROP the Created View
Let's delete the view from the database with the help of DROP statement. Write the below statement to drop the view:
DROP view products_list;
//try to access the dropped view
select * from product_info ;
Output:
ERROR at line 1:
ORA-00942: table or view does not exist
Explanation: The above output shows the view is not present in the database. So, the view is successfully dropped from the database.
Let's delete the another view from the database with the help of DROP statement. Write the below statement to drop the view:
DROP view expensive_products;
//try to access the dropped view
select * from expensive_products;
Output:
ERROR at line 1:
ORA-00942: table or view does not exist
Explanation:The above output shows the view is not present in the database. So, the view is successfully dropped from the database.
Conclusion
In conclusion, the PL/SQL DROP VIEW statement is a powerful tool for managing database views. It allows administrators to remove unnecessary views, keeping the database schema organized and optimized. Understanding how to effectively use the DROP VIEW statement is essential for maintaining a clean and efficient database environment.
Similar Reads
SQL - DROP 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 our database schema. In SQL, deleting a view is straightforward using the DROP VIEW command. In this article, we will explain
5 min read
MySQL - Drop View
MySQL is a powerful open-source relational database management system that is widely used for building scalable and high-performance databases. Developed by MySQL AB, which is currently owned by Oracle Corporation, MySQL has been around since 1995. It is known for its robust, easy-to-use, and reliab
5 min read
SQLite DROP VIEW
SQLite is an embedded database that doesn't use a database like Oracle in the background to operate. It is written in C language and is used by developers who embed a lightweight database over the existing application, browser, or embedded systems. The main features of SQLite are that it is a tiny,
4 min read
PL/SQL VIEW
In Oracle PL/SQL, views are a powerful way to manage data access and simplify complex queries. A view is essentially a virtual table that presents data from one or more tables using a stored query. Unlike physical tables, views do not store the data themselves; they dynamically retrieve data based o
4 min read
PL/SQL Drop Triggers
In database management, triggers play an important role in maintaining data integrity and enforcing business rules automatically. However, there may be situations where we need to remove an existing trigger from a database. This process is accomplished using the DROP TRIGGER statement in PL/SQL.In t
4 min read
PL/SQL CREATE VIEW
PL/SQL CREATE VIEW is a statement used to create a virtual table based on the result of a query. Views in PL/SQL allow users to access and manipulate data stored in one or more underlying tables as if it were a single table. In this article, We will learn about the PL/SQL CREATE VIEW by understandin
3 min read
SQL DROP TABLE
The DROP TABLE command in SQL is a powerful and essential tool used to permanently delete a table from a database, along with all of its data, structure, and associated constraints such as indexes, triggers, and permissions. When executed, this command removes the table and all its contents, making
4 min read
PL/SQL Drop Index
In PL/SQL an index is a database object that improves the speed of the data retrieval operations on the table. However, there are situations where we might want to remove an index either to optimize performance or to retrieve disk space. In this article, we will provide a comprehensive guide on how
4 min read
PL/SQL Copy Table
Copying tables in PL/SQL is a common task in database management. It involves duplicating the structure and data of an existing table into a new one. This operation can be accomplished using the CREATE TABLE AS SELECT statement, which allows for the creation of a new table based on the result set of
3 min read
PL/SQL RENAME VIEW
PL/SQL which is Oracle Corporation's extension of SQL with a procedural language enables developers and database administrators to carry out complex operations in the databases. One of the frequently performed operations in the process of database maintenance is the change of names of objects to acc
3 min read