SQL DELETE VIEW
A VIEW in SQL is a virtual table created based on a query, providing a simplified representation of the data without storing it physically. While you cannot delete rows directly from a view unless it is an updatable view, you can remove the view itself using the DROP VIEW statement.
Dropping a view does not affect the underlying data in the source table(s); it simply removes the view definition from the database.
Example
This example demonstrates deleting a view named HighPricedProducts, which was created to show products priced above $500.
Code Example
-- Drop the view HighPricedProducts
DROP VIEW HighPricedProducts;
-- Verify the view is deleted
SHOW FULL TABLES WHERE Table_Type = 'VIEW';
Output
Tables_in_SalesDB | Table_Type |
---|---|
Orders | BASE TABLE |
Customers | BASE TABLE |
Explanation
- The DROP VIEW command removes the HighPricedProducts view from the database.
- The SHOW FULL TABLES command verifies the remaining tables and views in the database.
- The underlying data in the source tables remains unaffected.