documentation/query/sql/drop-view.md
Removes a view from the database. The view definition is deleted, but underlying tables are not affected.
For more information on views, see the Views documentation.
DROP VIEW [ IF EXISTS ] view_name
| Parameter | Description |
|---|---|
IF EXISTS | Prevents error if view doesn't exist |
view_name | Name of the view to drop |
DROP VIEW my_view
To avoid errors when the view might not exist:
DROP VIEW IF EXISTS my_view
Views must be dropped one at a time:
DROP VIEW view1;
DROP VIEW view2;
DROP VIEW view3;
When a view is dropped, any views that reference it become invalid:
-- Create view hierarchy
CREATE VIEW level1 AS (SELECT * FROM trades WHERE price > 0);
CREATE VIEW level2 AS (SELECT * FROM level1 WHERE quantity > 0);
-- Drop base view
DROP VIEW level1;
-- level2 is now invalid
SELECT view_status FROM views() WHERE view_name = 'level2';
-- Returns: invalid
If the dropped view is later recreated, dependent views automatically become valid again.
| Error | Cause |
|---|---|
view does not exist [view=name] | View doesn't exist and IF EXISTS not specified |
Access denied [DROP VIEW on view_name] | User lacks DROP VIEW permission (Enterprise) |
Dropping a view requires the DROP VIEW permission on that view:
-- Grant DROP VIEW permission to a user
GRANT DROP VIEW ON my_view TO username;
-- Grant DROP VIEW permission on multiple views
GRANT DROP VIEW ON view1, view2 TO username;
When a user creates a view, they are automatically granted all permissions
including DROP VIEW on that view.