ALTER VIEW

语法说明

ALTER VIEW 用于更改视图。

如果语法参数列表中命名的视图不存在,则语句报错:该视图无效。

语法结构

  1. > ALTER VIEW view_name [(column_list)]
  2. AS select_statement
  3. [WITH [CASCADED | LOCAL] CHECK OPTION]

示例

  1. drop table if exists t1;
  2. create table t1 (a int);
  3. insert into t1 values(1),(2),(3),(4);
  4. create view v5 as select * from t1;
  5. mysql> select * from v5;
  6. +------+
  7. | a |
  8. +------+
  9. | 1 |
  10. | 2 |
  11. | 3 |
  12. | 4 |
  13. +------+
  14. 4 rows in set (0.01 sec)
  15. alter view v5 as select * from t1 where a=1;
  16. mysql> select * from v5;
  17. +------+
  18. | a |
  19. +------+
  20. | 1 |
  21. +------+
  22. 1 row in set (0.01 sec)
  23. alter view v5 as select * from t1 where a > 2;
  24. mysql> select * from v5;
  25. +------+
  26. | a |
  27. +------+
  28. | 3 |
  29. | 4 |
  30. +------+
  31. 2 rows in set (0.00 sec)