This topic describes how to drop a view.
Syntax
You can use the DROP VIEW statement to drop one or more views.
Note
To execute this statement, you must have the
DROPprivilege for each view.
drop_view_stmt:
DROP VIEW [IF EXISTS] view_name_list [CASCADE | RESTRICT];
view_name_list:
view_name [, view_name_list]
Parameters
| Parameter | Description |
|---|---|
| IF EXISTS | The IF EXISTS keyword prevents the error that occurs because a view to be dropped does not exist. |
| view_name_list | If view_name_list contains views that do not exist, an error may be reported during execution but the specified views that exist are dropped. |
| CASCADE | RESTRICT | CASCADE indicates that the objects dependent on the view are automatically removed. RESTRICT indicates that the view cannot be dropped if an object dependent on the view exists.
Note |
Examples
Example 1
Drop the v1 view.
obclient> DROP VIEW v1;
Query OK, 0 rows affected
Example 2
Drop the v1 and v2 views.
obclient> DROP VIEW IF EXISTS v1,v2;
Query OK, 0 rows affected, 1 warning
Note
If the
IF EXISTSkeyword is not used and thev1view does not exist in the database, neither of the views can be dropped.obclient> DROP VIEW v1,v2; ERROR 1051 (42S02): Unknown table 'ny.v1'If the
IF EXISTSkeyword is used, thev2view can be dropped even if thev1view does not exist in the database.obclient> DROP VIEW IF EXISTS v3,v4; Query OK, 0 rows affected, 2 warnings