Mysql实验六

一、在员工管理数据库YGGL中创建视图Emp_view1,包含所有男员工的员工编号、姓名、工作年限和学历。

create or replace view Emp_view1 as select 员工编号,姓名,工作年限,学历 from employess where employess.性别=1;

create view Emp_view1 as select 员工编号,姓名,工作年限,学历 from employess where 性别="1";

二、从Emp_view1查询工作年限在两年以上的员工信息。

select * from Emp_view1 where 工作年限>2;

三、创建视图 Emp_view 2,包含员工号码、姓名、所在部门名称和收入。

create or replace view Emp_view2 as select employess.员工编号, employess.姓名,Deparments.部门名称,Salary.收入 from employess,Deparments,Salary where employess.员工部门号 = Deparments.部门编号 and employess.员

工编号 = Salary.员工编号;

四、从Emp view2 查询研发部的员工号码、姓名和收入。

select 员工编号,姓名,收入 from Emp_view2 where 部门名称= '研发部';

五、创建视图 Emp_ view3,包含所有工作年限2年以上的员工的员工号码、姓名、学历、出生日期、性别、工作年限和所在部门编号。在创建视图的时候加上 WITH CHECKOPTION 子句。

create or replace view Emp_view3 as select 员工编号,姓名,学历,出生日期,性别,工作年限,员工部门号 from employess where 工作年限>=2 with check option;

六、在 Emp_view3 插入一条记录:(041110,钟晓玲,博士,1973-12-01,男,3,4)

insert into Emp_view3 values ('041110','钟晓玲','博士','1973-12-01','1','3','4');

七、修改视图 Emp view2 中将“李丽”的收入加 200 元。

update Emp_view2 set 收入=收入+200 where 姓名='李丽';

八、删除视图 Emp_view3 中“本科”学历的员工。

delete from Emp_view3 where 学历='本科';

九、修改视图 Emp_view1,包含员工号码、姓名和实际收入。

alter view Emp_view1 as select employess.员工编号,姓名,Salary.收入 from employess,Salary where employess.员工编号=Salary.员工编号;

十、删除视图 Emp_view2 和 Emp_view3。

drop view Emp_view2,Emp_view3;