View MySQL
View: This is a virtual table that can also be used as a data source for the SELECT statement. Under certain certain conditions, it can be done in the table by watching. Data in a view does not take up as much space as tables and indexes. The SELECT statement is stored only in the view.
The role of gaze:
-
Keep the process simple: For a complex SELECT statement, it can be wrapped as a view.
-
Avoid redundant data: because the view is saved with a SELECT statement. All data is stored in a database table so that different views can be set for one or several tables to provide services for different applications, avoiding data duplication.
-
Enhanced data security: It can customize different views for different users and understand that different users can only query or modify the relevant data.
Create View: Create the view name [(((список поля зрения)] Like the SELECT statement
Drop View: Drop View View Name
mysql> select * from user;
+----+--------+--------+--------+
| id | name | gender | stu_no |
+----+--------+--------+--------+
| 1 | Zhang San | M | 1 |
| 2 | Lee Four | F | 2 |
| 3 | bob | M | 4 |
| 4 | Wang Five | M | 1 |
| 5 | alias | M | 6 |
+----+--------+--------+--------+
5 rows in set (0.00 sec)
mysql> select id,name,gender from user;
+----+--------+--------+
| id | name | gender |
+----+--------+--------+
| 1 | Zhang San | M |
| 2 | li si | f |
| 3 | bob | M |
| 4 | Wang wu | m |
| 5 | alias | M |
+----+--------+--------+
5 rows in set (0.00 sec)
mysql> create view demo as select id,name,gender from user;
Query OK, 0 rows affected (0.04 sec)
mysql> select * from demo;
+----+--------+--------+
| id | name | gender |
+----+--------+--------+
| 1 | Zhang San | M |
| 2 | li si | f |
| 3 | bob | M |
| 4 | Wang wu | m |
| 5 | alias | M |
+----+--------+--------+
5 rows in set (0.10 sec)
Normal view: The default creation view creates regular views
Modify the original table with regular views
mysql> insert into demo values(6,'john','F');
Query OK, 1 row affected (0.00 sec)
mysql> select * from user;
+----+--------+--------+--------+
| id | name | gender | stu_no |
+----+--------+--------+--------+
| 1 | Zhang San | M | 1 |
| 2 | Lee Four | F | 2 |
| 3 | bob | M | 4 |
| 4 | Wang Five | M | 1 |
| 5 | alias | M | 6 |
| 6 | john | F | NULL |
+----+--------+--------+--------+
6 rows in set (0.00 sec)
View validation: use “with[local|cascading][локальным|каскадным»[محلي|المتتالية”[локальным|каскадным»
mysql> create view demo1 as select * from user where id < 5 with local check option;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from demo1;
+----+--------+--------+--------+
| id | name | gender | stu_no |
+----+--------+--------+--------+
| 1 | Zhang San | M | 1 |
| 2 | Lee Four | F | 2 |
| 3 | bob | M | 4 |
| 4 | Wang Five | M | 1 |
+----+--------+--------+--------+
4 rows in set (0.10 sec)
#At На этот раз представление имеет функцию проверки, не соответствует требованиям, где положения, и проверяют представление, чтобы добавить исключение.
mysql> insert into demo1 values(6,'abc','F',1);
ERROR 1369 (HY000): CHECK OPTION failed 'student.demo1'
Local and consecutive check type
When an attempt is made to use with the validate option or with the validate option, CSACADED, like the view, indicates that the view is sequential. When used with the local check option
-
Local rendering: In action, with a view check, only assertions that match the check conditions can be executed.
-
Cascading view(class view, create another view based on the view): The statement that matches the validation conditions will be executed for all views.