Skip to main content
Version: V1.0.0

ALTER VIEW

Description

This statement is used to modify the definition of a view.

Privilege requirements

To execute the ALTER VIEW statement, the current user must have the DROP and CREATE VIEW privileges. For more information about the privileges in seekdb, see Privilege classification.

Syntax

ALTER VIEW view_name [(column_name_list)]
AS select_stmt;

column_name_list:
column_name [, column_name ...]

Parameters

ParameterDescription
view_nameThe name of the view.
column_name_listOptional. The list of column names in the view. If not specified, the column names retrieved by the SELECT statement will be used as the view column names. The columns retrieved by the SELECT statement can be simple references to table columns, or expressions involving functions, constants, operators, etc. The view column names have the following limitations:
  • Each column name must be unique and cannot be repeated.
  • The number of names in column_name_list must equal the number of columns retrieved by the SELECT statement.
column_nameThe name of the view column.
select_stmtThe query (SELECT) statement used to define the view. It specifies the view's definition, allowing data to be selected from the base table or other views. For more information about the specific structure and options of the query statement, see SELECT statement.

Examples

Modify the definition of the view v1 to select data from test_tbl2.

  1. Create the table test_tbl1.

    CREATE TABLE test_tbl1 (col1 INT, col2 INT);
  2. Create the view v1 based on the table test_tbl1.

    CREATE VIEW v1
    AS SELECT * FROM test_tbl1;
  3. Create the table test_tbl2.

    CREATE TABLE test_tbl2 (col1 INT, col2 INT, col3 INT);
  4. Modify the definition of the view v1 to select data from test_tbl2.

    ALTER VIEW v1 AS SELECT * FROM test_tbl2;
  5. View the definition of the view v1 again.

    SHOW CREATE VIEW v1;

    The result is as follows:

    +------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
    | View | Create View | character_set_client | collation_connection |
    +------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
    | v1 | CREATE VIEW `v1` AS select `db_test`.`test_tbl2`.`col1` AS `col1`,`db_test`.`test_tbl2`.`col2` AS `col2`,`db_test`.`test_tbl2`.`col3` AS `col3` from `db_test`.`test_tbl2` | utf8mb4 | utf8mb4_general_ci |
    +------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
    1 row in set (0.001 sec)

References