View, which combines some data from a base table into a form of a virtual table, is called virtual because it exists only when the view is used in a single statement. At the same time, if the data in the view is modified, the data in the base table is also modified. Creating a view: Create [or replace] view view_name [Column1,column2 ...] As table expression as: Create a View towns,1. Contains all the city names in the players table, 2. Next, and query the contents of this virtual table 1. Create VIEW towns as Select Town from Players2. SELECT * FROM towns above is the first to create a view towns, then query the view, where the column name of the view is not explicitly written out, so the default is the field of the query after the Column Name field, as the result of the query as the view data, you can explicitly specify the view column name as: Create View Cplays (uid,name,job) asselect id,name,prefessionfrom works Remove id = 100 from view cplays the person delete from Cplayswhere UI d = 100 the person with id = 100 in the base table will be deleted at the same time allow an expression in select to be a function or calculate as:create or replace view result Asselect grand, COUNT (*) from score When group by grand queries the above view: SELECT * from result returns a field with Grand,count (*) or replace when the view is present, updates the view if there is no constraint, as follows: CREATE VIEW T_ View Asselect id,name,jobfrom test.workwhere ID < 4;update t_view set name = ' xxx ' where id = 4; The above statement will change the name of id = 4 to ' X xx ', no problem, but when the constraint is added, the appropriate action is not allowed if the condition is not met as:create view T_view asselect id,name,jobfrom test.workwhere ID < 4with check Option;update T_vieW Set name = ' xxx ' where id = 4; The above update will fail because the view is constrained, the ID of the subsequent query is not in the created view, the related data cannot be updated, and because the view can be nested, so if the operation of the previous view is detected, use the with local The CHECK option constraint allows only the current view condition to be detected, and if the nested view associated with it is checked, the constraint is with[cascaded] Check option, which by default is the delete view of the cascaded. If exitsts] View_name
MySQL view of the database