[MySQL learning articles] --- view

[MySQL Learning Article]-View

View reference

The management level of a company is from high to low as regional directors, department heads, and team leaders; now, for safety reasons, there is a requirement: the three types of people need to be provided with different viewing rights in the employee information table:

​ Regional Supervisor: Can see all employee information

​ Department head: see the employee name, phone number, ID number

​ Leader: Only the employee’s name and phone number can be seen

At this time, you can introduce a view-build a virtual table on the basis of the real table, let them see the view, rather than the real table.

Build a view: create view view name as query statement;

Query statement The result of the query is the information that needs to be displayed to these three types of people

CREATE VIEW view_all 
AS SELECT d.deptName,e.empNmae,e.salary FROM dept d JOIN  emp e ON d.`id`=e.`deptId`;

view

View/delete view

#查看视图
SELECT * FROM view_all;

#删除视图
DROP VIEW view_all;

Guess you like

Origin blog.csdn.net/DREAM_yao/article/details/108167816