ip between the
rows in the view and the rows in the underlying table. There are also certain
other constructs that make a view non-updatable. See Inserting and Updating
with Views.

WITH CHECK OPTION
-----------------

The WITH CHECK OPTION clause can be given for an updatable view to prevent
inserts or updates to rows except those for which the WHERE clause in the
select_statement is true.

In a WITH CHECK OPTION clause for an updatable view, the LOCAL and CASCADED
keywords determine the scope of check testing when the view is defined in
terms of another view. The LOCAL keyword restricts the CHECK OPTION only to
the view being defined. CASCADED causes the checks for underlying views to be
evaluated as well. When neither keyword is given, the default is CASCADED.

For more information about updatable views and the WITH CHECK OPTION clause,
see Inserting and Updating with Views.

IF NOT EXISTS
-------------

MariaDB starting with 10.1.3
----------------------------
The IF NOT EXISTS clause was added in MariaDB 10.1.3

When the IF NOT EXISTS clause is used, MariaDB will return a warning instead
of an error if the specified view already exists. Cannot be used together with
the OR REPLACE clause.

Atomic DDL
----------

MariaDB starting with 10.6.1
----------------------------
MariaDB 10.6.1 supports Atomic DDL and CREATE VIEW is atomic.

Examples
--------

CREATE TABLE t (a INT, b INT) ENGINE = InnoDB;

INSERT INTO t VALUES (1,1), (2,2), (3,3);

CREATE VIEW v AS SELECT a, a*2 AS a2 FROM t;

SELECT * FROM v;
+------+------+
| a    | a2   |
+------+------+
|    1 |    2 |
|    2 |    4 |
|    3 |    6 |
+------+------+

OR REPLACE and IF NOT EXISTS:

CREATE VIEW v AS SELECT a, a*2 AS a2 FROM t;
ERROR 1050 (42S01): Table 'v' already exists

CREATE OR REPLACE VIEW v AS SELECT a, a*2 AS a2 FROM t;
Query OK, 0 rows affected (0.04 sec)

CREATE VIEW IF NOT EXISTS v AS SELECT a, a*2 AS a2 FROM t;
Query OK, 0 rows affected, 1 warning (0.01 sec)

SHOW WARNINGS;
+-------+------+--------------------------+
| Level | Code | Message                  |
+-------+------+--------------------------+
| Note  | 1050 | Table 'v' already exists |
+-------+------+--------------------------+

URL: https://mariadb.com/kb/en/create-view/