DROP VIEW

2023-07-28 02:55:42  Updated

Purpose

You can use this statement to drop one or more views.

Notice

To execute this statement, you must have the DROP privilege for each view.

Syntax

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 the 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 specifies that the objects dependent on the view are automatically dropped. RESTRICT specifies that the view cannot be dropped if an object that depends on the view exists.
Note The current version does not support this parameter. If this parameter is specified, it will be parsed and ignored.

Examples

  • Drop the v1 view.

    obclient> DROP VIEW v1;
    Query OK, 0 rows affected (0.02 sec)
    
  • Drop the v1 and v2 views.

    obclient> DROP VIEW IF EXISTS v1,v2;
    Query OK, 0 rows affected, 1 warning (0.01 sec)
    
  • Drop multiple views without using the IF EXISTS clause. If a view does not exist, an error is returned.

    obclient> DROP VIEW v1,v2;
    ERROR 1051 (42S02): Unknown table 'test.v1'
    

Contact Us