DROP VIEW

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

语法图

DropViewStmt:

DropViewStmt

TableNameList:

TableNameList

TableName:

TableName

示例

  1. mysql> CREATE TABLE t1 (id INT NOT NULL PRIMARY KEY auto_increment, c1 INT NOT NULL);
  2. Query OK, 0 rows affected (0.11 sec)
  3. mysql> INSERT INTO t1 (c1) VALUES (1),(2),(3),(4),(5);
  4. Query OK, 5 rows affected (0.03 sec)
  5. Records: 5 Duplicates: 0 Warnings: 0
  6. mysql> CREATE VIEW v1 AS SELECT * FROM t1 WHERE c1 > 2;
  7. Query OK, 0 rows affected (0.11 sec)
  8. mysql> SELECT * FROM t1;
  9. +----+----+
  10. | id | c1 |
  11. +----+----+
  12. | 1 | 1 |
  13. | 2 | 2 |
  14. | 3 | 3 |
  15. | 4 | 4 |
  16. | 5 | 5 |
  17. +----+----+
  18. 5 rows in set (0.00 sec)
  19. mysql> SELECT * FROM v1;
  20. +----+----+
  21. | id | c1 |
  22. +----+----+
  23. | 3 | 3 |
  24. | 4 | 4 |
  25. | 5 | 5 |
  26. +----+----+
  27. 3 rows in set (0.00 sec)
  28. mysql> DROP VIEW v1;
  29. Query OK, 0 rows affected (0.23 sec)
  30. mysql> SELECT * FROM t1;
  31. +----+----+
  32. | id | c1 |
  33. +----+----+
  34. | 1 | 1 |
  35. | 2 | 2 |
  36. | 3 | 3 |
  37. | 4 | 4 |
  38. | 5 | 5 |
  39. +----+----+
  40. 5 rows in set (0.00 sec)

MySQL 兼容性

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

See also