MySQL之视图

一、创建视图

create view 视图名

as

查询语句;select * from 视图名 where 查询条件;

二、视图的修改 

select * from v_ysq

1、方式一:

语法:create or replace view 视图名 as 查询语句;

例题:

CREATE OR REPLACE VIEW v_mwy AS SELECT AVG(age),tid FROM emp GROUP BY tid;

2、方式二:

语法:alter view 视图名 as 查询语句;

例题: ALTER VIEW v_mwy AS SELECT * FROM emp;
 

三、删除视图

语法:drop view 视图名,视图名,...;

例题:DROP VIEW v_mwy ,v_m1,v_m2;

四、查看视图

语法:DESC 视图名;

SHOW CREATE VIEW v_ysq;

五、视图的更新

CREATE OR REPLACE VIEW myv1

AS

SELECT last_name,email,salary*12*(1+IFNULL(commission_pct,0)) "annual salary"

FROM employees;

​

CREATE OR REPLACE VIEW myv1

AS

SELECT last_name,email

FROM employees;

#1.插入

INSERT INTO myv1 VALUES('张三','zf@qq.com')

#2.修改

UPDATE myv1 SET last_name = '张三' WHERE last_name='李四';

#3.删除

DELETE FROM myv1 WHERE last_name = '张三';

上一篇:SpinnerViewPop【PopWindow样式(单选)、Dialog样式(单选+多选)的下拉菜单】


下一篇:剑指 Offer 22. 链表中倒数第k个节点