title: DROP VIEW summary: TiDB 数据库中 DROP VIEW 的使用概况。

DROP VIEW

DROP VIEW 语句用于从当前所选定的数据库中删除视图对象。视图所引用的基表不受影响。

语法图

  1. DropViewStmt ::=
  2. 'DROP' 'VIEW' ( 'IF' 'EXISTS' )? TableNameList RestrictOrCascadeOpt
  3. TableNameList ::=
  4. TableName ( ',' TableName )*
  5. TableName ::=
  6. Identifier ('.' Identifier)?

示例

  1. CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, c1 INT NOT NULL);
  1. Query OK, 0 rows affected (0.11 sec)
  1. INSERT INTO t1 (c1) VALUES (1),(2),(3),(4),(5);
  1. Query OK, 5 rows affected (0.03 sec)
  2. Records: 5 Duplicates: 0 Warnings: 0
  1. CREATE VIEW v1 AS SELECT * FROM t1 WHERE c1 > 2;
  1. Query OK, 0 rows affected (0.11 sec)
  1. SELECT * FROM t1;
  1. +----+----+
  2. | id | c1 |
  3. +----+----+
  4. | 1 | 1 |
  5. | 2 | 2 |
  6. | 3 | 3 |
  7. | 4 | 4 |
  8. | 5 | 5 |
  9. +----+----+
  10. 5 rows in set (0.00 sec)
  1. SELECT * FROM v1;
  1. +----+----+
  2. | id | c1 |
  3. +----+----+
  4. | 3 | 3 |
  5. | 4 | 4 |
  6. | 5 | 5 |
  7. +----+----+
  8. 3 rows in set (0.00 sec)
  1. DROP VIEW v1;
  1. Query OK, 0 rows affected (0.23 sec)
  1. SELECT * FROM t1;
  1. +----+----+
  2. | id | c1 |
  3. +----+----+
  4. | 1 | 1 |
  5. | 2 | 2 |
  6. | 3 | 3 |
  7. | 4 | 4 |
  8. | 5 | 5 |
  9. +----+----+
  10. 5 rows in set (0.00 sec)

MySQL 兼容性

DROP VIEW 语句与 MySQL 完全兼容。如发现任何兼容性差异,请在 GitHub 上提交 issue

See also