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之视图的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-02MySQL集群项目实战:新手入门指南
- 2024-11-02初学者指南:部署MySQL集群资料
- 2024-11-01部署MySQL集群教程:新手入门指南
- 2024-11-01如何部署MySQL集群:新手入门教程
- 2024-11-01部署MySQL集群学习:新手入门教程
- 2024-11-01部署MySQL集群入门:新手必读指南
- 2024-10-23BinLog入门:新手必读的MySQL二进制日志指南
- 2024-10-23Binlog入门:MySQL数据库的日志管理指南
- 2024-10-22MySQL数据库入门教程:从安装到基本操作
- 2024-10-22MySQL读写分离入门教程:轻松实现数据库性能提升