Brief introduction
Concept of the 1 view
2 · Create a view
3 • Working with views
Concept of the 1 view
What is a view, let's give an example:
A boss want to understand a few warehouse specific information, want to know how many of the warehouse inside also how much rice, flour, how many kinds, so sent a good Gan Xiao Wang to inventory goods, Xiao Wang ran very far after finally counted the return to the boss. Because the boss's business is very good, the contents of the warehouse often change, then the boss needs to know a few warehouse inventory details, and send Xiao Wang to count. So to go back and forth, the boss think Xiao Wang Tai hard, also not easy, the boss on a few people, a staff guarding warehouse 1,b staff guarding warehouse 2,c staff guard Warehouse 3. This does not need to go back and forth, the boss need to know the warehouse details, ask a, B, C employees, employees only need to be responsible for reporting on the line.
As with data, each time you need to find one of the information in this table, you need to write a long command, and the role of the view is no longer need to use a bar of command to see, but only need to see the view on the number, so the view is just a virtual table, itself does not store data. Only one result that is queried in the direction specified is selected separately.
To create a view:
Before you start, you've created a table that is a school transcript, because the results change every time the exam changes, so here we create a view of the students with a score of 90 or more. Is the data for the table:
To create a view command:
Command format: CREATE VIEW name as (condition 1, Condition 2 ...) )
For example, create a view with a score greater than 90.
Mysql> CREATE VIEW score _view as select from school where score > 80;
To view the view:
Mysql> Show tables;
Add one student to the table with a score greater than 90; Add a student with less than 90 data. Again to query for changes in the view. You will see the corresponding changes in the view, changing with the table! are related to each other.
To delete a view:
Syntax structure: drop view name;
mysql> drop view score _view;
Query OK, 0 rows affected (0.01 sec)
MySQL database view: View definition, create view, modify view