DROP-MATERIALIZED-VIEW

Name

DROP MATERIALIZED VIEW

Description

该语句用于删除物化视图。同步语法

语法:

  1. DROP MATERIALIZED VIEW [IF EXISTS] mv_name ON table_name;
  1. IF EXISTS: 如果物化视图不存在,不要抛出错误。如果不声明此关键字,物化视图不存在则报错。

  2. mv_name: 待删除的物化视图的名称。必填项。

  3. table_name: 待删除的物化视图所属的表名。必填项。

Example

表结构为

  1. mysql> desc all_type_table all;
  2. +----------------+-------+----------+------+-------+---------+-------+
  3. | IndexName | Field | Type | Null | Key | Default | Extra |
  4. +----------------+-------+----------+------+-------+---------+-------+
  5. | all_type_table | k1 | TINYINT | Yes | true | N/A | |
  6. | | k2 | SMALLINT | Yes | false | N/A | NONE |
  7. | | k3 | INT | Yes | false | N/A | NONE |
  8. | | k4 | BIGINT | Yes | false | N/A | NONE |
  9. | | k5 | LARGEINT | Yes | false | N/A | NONE |
  10. | | k6 | FLOAT | Yes | false | N/A | NONE |
  11. | | k7 | DOUBLE | Yes | false | N/A | NONE |
  12. | | | | | | | |
  13. | k1_sumk2 | k1 | TINYINT | Yes | true | N/A | |
  14. | | k2 | SMALLINT | Yes | false | N/A | SUM |
  15. +----------------+-------+----------+------+-------+---------+-------+
  1. 删除表 all_type_table 的名为 k1_sumk2 的物化视图

    1. drop materialized view k1_sumk2 on all_type_table;

    物化视图被删除后的表结构

    1. +----------------+-------+----------+------+-------+---------+-------+
    2. | IndexName | Field | Type | Null | Key | Default | Extra |
    3. +----------------+-------+----------+------+-------+---------+-------+
    4. | all_type_table | k1 | TINYINT | Yes | true | N/A | |
    5. | | k2 | SMALLINT | Yes | false | N/A | NONE |
    6. | | k3 | INT | Yes | false | N/A | NONE |
    7. | | k4 | BIGINT | Yes | false | N/A | NONE |
    8. | | k5 | LARGEINT | Yes | false | N/A | NONE |
    9. | | k6 | FLOAT | Yes | false | N/A | NONE |
    10. | | k7 | DOUBLE | Yes | false | N/A | NONE |
    11. +----------------+-------+----------+------+-------+---------+-------+
  2. 删除表 all_type_table 中一个不存在的物化视图

    1. drop materialized view k1_k2 on all_type_table;
    2. ERROR 1064 (HY000): errCode = 2, detailMessage = Materialized view [k1_k2] does not exist in table [all_type_table]

    删除请求直接报错

  3. 删除表 all_type_table 中的物化视图 k1_k2,不存在不报错。

    1. drop materialized view if exists k1_k2 on all_type_table;
    2. Query OK, 0 rows affected (0.00 sec)

    存在则删除,不存在则不报错。

Keywords

  1. DROP, MATERIALIZED, VIEW

Best Practice