ALTER VIEW

Description

ALTER VIEW is used to alter an existing view.

If any of the views named in the syntax parameter list do not exist, the statement reports an error and cannot change those views that do not exist.

Syntax

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

Examples

  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)