DROP-MATERIALIZED-VIEW
Name
DROP MATERIALIZED VIEW
Description
This statement is used to drop a materialized view. Synchronous syntax
grammar:
1. DROP MATERIALIZED VIEW [IF EXISTS] mv_name ON table_name;
- IF EXISTS: Do not throw an error if the materialized view does not exist. If this keyword is not declared, an error will be reported if the materialized view does not exist.
- mv_name: The name of the materialized view to delete. Required.
- table_name: The name of the table to which the materialized view to be deleted belongs. Required.
Example
The table structure is
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. +----------------+-------+----------+------+------ -+---------+-------+
- Drop the materialized view named k1_sumk2 of the table all_type_table
1. drop materialized view k1_sumk2 on all_type_table;
The table structure after the materialized view is deleted
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. Drop a non-existent materialized view in the table 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]
The delete request reports an error directly 3. Delete the materialized view k1_k2 in the table all_type_table, if it does not exist, no error will be reported.
1. drop materialized view if exists k1_k2 on all_type_table;
2. Query OK, 0 rows affected (0.00 sec)
If it exists, delete it, if it does not exist, no error is reported.
Keywords
1. DROP, MATERIALIZED, VIEW
