MySQL之视图

2021/9/10 2:04:15

本文主要是介绍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 = '张三';



这篇关于MySQL之视图的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程