Outdated Version

You are viewing an older version of this section. View current production version.

ALTER VIEW

Atomically replace a view with a new view defined by a SELECT statement. ALTER VIEW is an online operation and will not cause concurrently executing queries to fail.

Syntax

ALTER
    [DEFINER = { user | CURRENT_USER }]
    [SCHEMA_BINDING = { ON | OFF }]
    VIEW view_name [(column_list)]
    AS select_statement

Remarks

  • ALTER VIEW atomically replaces view view_name with a new view defined by select_statement.
  • ALTER VIEW privileges are granted only to the user who created the view and to SUPER users. If a SUPER user alters a view, that user commandeers ALTER privileges from the user who created the view.
  • The DEFINER clause specifies the user that should be used for security checks when a view is referenced by a query. The default value is CURRENT_USER.
  • When SCHEMA_BINDING is set to ON, objects referenced by the view cannot be dropped if the view exists; you need to drop the view before dropping these objects. By default, SCHEMA_BINDING is set to OFF.
  • The user who runs ALTER DEFINER..VIEW must have the SUPER permission.

Examples

ALTER VIEW view1 AS SELECT * FROM customers WHERE user_id LIKE "CUS%";
ALTER DEFINER=`user7`@`127.0.0.1` VIEW view1 AS SELECT * FROM customers WHERE user_id LIKE "CUS%";

Related Topics