Purpose
You can use this statement to modify the definition of a view.
Syntax
ALTER VIEW view_name [(column_name_list)] AS select_stmt;
column_name_list:
column_name [, column_name ...]
Parameters
| Parameter | Description |
|---|---|
| select_stmt | A SELECT statement that defines a view. You can use this statement to query base tables or other views. |
| column_name_list | The column names in the view, which must be unique, like those in a base table. By default, the column names retrieved by the SELECT statement are used as the column names in the view. You can also use the optional column_name_list clause to define column names for a view. Separate multiple column names with commas (,). The number of column names in column_name_list must be equal to the number of columns retrieved by the SELECT statement. The SELECT statement can directly reference the columns of a table. You can also use functions, constants, and operators in the statement to retrieve columns. |
Examples
Change the definition of view v1 to selecting data from t2.
obclient> SHOW CREATE VIEW v1;
+------+-----------------------------------------------------------------------------------------------+----------------------+----------------------+
| View | Create View | character_set_client | collation_connection |
+------+-----------------------------------------------------------------------------------------------+----------------------+----------------------+
| v1 | CREATE VIEW `v1` AS select `test`.`T1`.`c1` AS `d1`,`test`.`T1`.`c2` AS `d2` from `test`.`T1` | utf8mb4 | utf8mb4_general_ci |
+------+-----------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set
obclient> ALTER VIEW v1 AS SELECT * FROM t2;
Query OK, 0 rows affected