VIEW_DEFINITIONcolumn has most of what you see in the
Create Tablefield that
SHOW CREATE VIEWproduces. Skip the words before
SELECTand skip the words
WITH CHECK OPTION. Suppose that the original statement was:
CREATE VIEW v AS SELECT s2,s1 FROM t WHERE s1 > 5 ORDER BY s1 WITH CHECK OPTION;
Then the view definition looks like this:
SELECT s2,s1 FROM t WHERE s1 > 5 ORDER BY s1
CHECK_OPTIONcolumn has a value of
MySQL sets a flag, called the view updatability flag, at
CREATE VIEWtime. The flag is set to
DELETE(and similar operations) are legal for the view. Otherwise, the flag is set to
IS_UPDATABLEcolumn in the
VIEWStable displays the status of this flag.
If a view is not updatable, statements such
INSERTare illegal and will be rejected. (Note that even if a view is updatable, it might not be possible to insert into it; for details, refer to Updatable and Insertable Views.)
IS_UPDATABLEflag may be unreliable if a view depends on one or more other views, and one of these underlying views is updated. Regardless of the
IS_UPDATABLEvalue, the server keeps track of the updatability of a view and correctly rejects data change operations to views that are not updatable. If the
IS_UPDATABLEvalue for a view has become inaccurate to due to changes to underlying views, the value can be updated by deleting and recreating the view.
DEFINER: The account of the user who created the view, in
SECURITY_TYPEhas a value of
CHARACTER_SET_CLIENT: The session value of the
character_set_clientsystem variable when the view was created.
COLLATION_CONNECTION: The session value of the
collation_connectionsystem variable when the view was created.
MySQL lets you use different
sql_mode settings to tell the
server the type of SQL syntax to support. For example, you might
ANSI SQL mode to ensure
MySQL correctly interprets the standard SQL concatenation
operator, the double bar (
||), in your queries.
If you then create a view that concatenates items, you might worry
that changing the
setting to a value different from
ANSI could cause the view to
become invalid. But this is not the case. No matter how you write
out a view definition, MySQL always stores it the same way, in a
canonical form. Here is an example that shows how the server
changes a double bar concatenation operator to a
mysql> SET sql_mode = 'ANSI'; Query OK, 0 rows affected (0.00 sec) mysql> CREATE VIEW test.v AS SELECT 'a' || 'b' as col1; Query OK, 0 rows affected (0.00 sec) mysql> SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'v'; +----------------------------------+ | VIEW_DEFINITION | +----------------------------------+ | select concat('a','b') AS `col1` | +----------------------------------+ 1 row in set (0.00 sec)
The advantage of storing a view definition in canonical form is
that changes made later to the value of
sql_mode will not affect the
results from the view. However an additional consequence is that
comments prior to
stripped from the definition by the server.