- 1.插入
INSERT INTO myv1 VALUES(‘张飞’,’zf@qq.com’);
#2.修改
UPDATE myv1 SET last_name = ‘张无忌’ WHERE last_name=’张飞’;
#3.删除
DELETE FROM myv1 WHERE last_name = ‘张无忌’; - 具备以下特点的视图不允许更新
#①包含以下关键字的SQL语句:
#分组函数、distinct、group by、having、union或者union all
#②常量视图
#③select中包含子查询
#④有用join的
#⑤from后面有一个不能更新的视图
#⑥where子句的子查询引用了from子句中的表
**注意视图一般是用于查询的, 基本不更新**
#二、视图的修改
#方式一:
/
create or replace view 视图名
as
查询语句;
/
SELECT FROM myv3;
CREATE OR REPLACE VIEW myv3
AS
SELECT AVG(salary),job_id
FROM employees
GROUP BY job_id;
#方式二:
/
语法:
alter view 视图名
as
查询语句:
/
ALTER VIEW myv3
AS
SELECT FROM employees;
#三、删除视图
/
语法:drop view 视图名,视图名……;
/
DROP VIEW myv1,myv2,myv3;
#四、查看视图
DESC myv3;
SHOW CREATE VIEW myv3;
#五、视图的更新
CREATE OR REPLACE VIEW myv1
AS
SELECT last_name,email,salary12(1+IFNULL(commission_pct,0)) AS 年薪
FROM employees;
CREATE OR REPLACE VIEW myv1
AS
SELECT last_name,email
FROM employees;
SELECT * FROM myv1;