--- view the role of mysql mysql view

Similar operation view showing an operation table

Mysql view of the role

Test Table: user have id, name, age, sex field
Test Table: goods have id, name, price field
Test Table: ug have id, userid, goodsid field

The role of view is too strong, and I experienced the following benefits:

A role:
    Improved reusability, just like a function. If you frequently get the user name and goods of name. You should use the following sql language. Example:
        select a.name as username, b.name as goodsname from user as a, goods as b, ug as c where a.id=c.userid and c.goodsid=b.id;
    But with the view not the same, create a view other. Examples
        create view other as select a.name as username, b.name as goodsname from user as a, goods as b, ug as c where a.id=c.userid and c.goodsid=b.id;
    After creating the view, so you can get a user name and goods of name. Example:
        select * from other;
    Sql statement above, you can get the user name and the name of the goods.
Role two:
    Reconstruction of the database, but do not affect the operation of the program. If for some needs, the user needs to demolition and Table UserB usera table, the structure of the following two tables:
        Test Table: usera have id, name, age field
        Test Table: userb has id, name, sex field
    Then if the client uses php sql statement: select * from user; it will prompt the table does not exist, then how to solve it. Solution: Create view. The following sql statement to create a view:
        create view user as select a.name,a.age,b.sex from usera as a, userb as b where a.name=b.name;
        These assumptions name is unique. At this end use php sql statement: select * from user; what the error will not. This enables changes to the database structure, does not change the function of the script.
Three functions:
    Improve the safety performance. Different users can set different views. For example: a user can obtain the name and age of the user table data, sex data can not be acquired. So you can create a view. Examples are as follows:
        create view other as select a.name, a.age from user as a;
    In this case, the use of the sql statement: select * from other; at most it can only get the data name and age, and other data will not be acquired.
Test Table: user have id, name, age, sex field
Test Table: goods have id, name, price field
Test Table: ug have id, userid, goodsid field

The role of view is too strong, and I experienced the following benefits:

A role:
    Improved reusability, just like a function. If you frequently get the user name and goods of name. You should use the following sql language. Example:
        select a.name as username, b.name as goodsname from user as a, goods as b, ug as c where a.id=c.userid and c.goodsid=b.id;
    But with the view not the same, create a view other. Examples
        create view other as select a.name as username, b.name as goodsname from user as a, goods as b, ug as c where a.id=c.userid and c.goodsid=b.id;
    After creating the view, so you can get a user name and goods of name. Example:
        select * from other;
    Sql statement above, you can get the user name and the name of the goods.
Role two:
    Reconstruction of the database, but do not affect the operation of the program. If for some needs, the user needs to demolition and Table UserB usera table, the structure of the following two tables:
        Test Table: usera have id, name, age field
        Test Table: userb has id, name, sex field
    Then if the client uses php sql statement: select * from user; it will prompt the table does not exist, then how to solve it. Solution: Create view. The following sql statement to create a view:
        create view user as select a.name,a.age,b.sex from usera as a, userb as b where a.name=b.name;
        These assumptions name is unique. At this end use php sql statement: select * from user; what the error will not. This enables changes to the database structure, does not change the function of the script.
Three functions:
    Improve the safety performance. Different users can set different views. For example: a user can obtain the name and age of the user table data, sex data can not be acquired. So you can create a view. Examples are as follows:
        create view other as select a.name, a.age from user as a;
    In this case, the use of the sql statement: select * from other; at most it can only get the data name and age, and other data will not be acquired.

Guess you like

Origin www.cnblogs.com/huang99882008/p/11112170.html