创建一个视图:
create view emp_salary_view as (select * from employees where salary>2000);
此时就出现一个视图:
select * from emp_salary_view esv where job='销售';
覆盖视图:
create or replace view emp_salary_view as (select * from employees where job='售后');
删除视图
drop view emp_salary_view;
Algorithm参数
- merge 可以更新真实表中的数据
- temptable 不可以更新表中的数据
- undefined 没有定义该参数,但是默认为merge,因为MySql认为这样更有效
检查
with check option
这样再修改视图中的数据后,会对修改的内容做检测,如果不符合where条件就不允许数据修改create view emp_salary_view as (select * from employees where salary>2000) with check option;
视图不可更新部分
如果视图中的数据不是直接来源于基表,那么这个字段的数据是无法进行操作的
列如:avg(salary) 、sum(salary)等