当前位置:网站首页>Mysql8.026-- view (bottom)
Mysql8.026-- view (bottom)
2022-07-19 04:45:00 【new DFP】
1. View
- Concept
① View , It can be regarded as a virtual table , Itself does not store data . The essence of view , It can be regarded as stored SELECT sentence
② In the view SELECT The table involved in the statement , Called the base table
③ Do... For the view DML operation , It will affect the data in the corresponding base table . vice versa .
④ Deletion of the view itself , It will not cause the deletion of data in the base table .
⑤ Application scenarios of view : For small projects , Views are not recommended . For large projects , Consider using views .
⑥ Benefits of views : Simplify queries ; Control data access
1.1 Create view
CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] VIEW View name [( Field list )] AS Query statement [WITH [CASCADED|LOCAL] CHECK OPTION]create view View name
as Query statement
-- Create view
CREATE VIEW v1
as
SELECT employee_id,last_name,salary
FROM atguigudb.employees
WHERE department_id=80
-- Query view
SELECT * FROM v1;
-- or REPLACE View substitution exists () Specify alternate field name
CREATE OR REPLACE VIEW v1(e_id,e_name,e_salary)
as
SELECT employee_id,last_name,salary
FROM atguigudb.employees
WHERE department_id=80
-- Create a view based on the view
CREATE VIEW v2
as
SELECT e_id,e_name
FROM v1
SELECT * from v2
-- Multiple tables associated query
create OR REPLACE VIEW morev
as
SELECT e.employee_id,e.last_name,d.department_name
from atguigudb.departments d , atguigudb.employees e
WHERE d.department_id=e.department_id
SELECT * FROM morev
CREATE OR REPLACE VIEW morev2
as
SELECT e.employee_id,e.last_name,d.department_name
FROM atguigudb.departments d LEFT join atguigudb.employees e
ON d.department_id=e.department_id
-- Format view
CREATE or REPLACE VIEW depart
as
SELECT CONCAT(e.last_name,'(',d.department_name,')') as emp_dept
from atguigudb.departments d , atguigudb.employees e
WHERE d.department_id=e.department_id
select *
FROM depart
1.2 Update the view
select * FROM v1
# Update data for view , This will lead to the modification of data in the base table
# Empathy , Update the data in the table , It will also lead to the modification of the data in the view
# Delete data from view , It will also lead to the deletion of data in the table
-- Update the view
update v1
set e_name="DFP"
WHERE e_id=145
-- Modify the view
-- It can be used or REPLACE
SHOW TABLES;
1.3 Delete view
#6. Delete view
DROP VIEW v1
DROP VIEW IF EXISTS v1边栏推荐
- 赚钱大师小程序【最新版5.9.9】商城/佣金即时提现/分销推广/话费充值/美团饿了么外卖
- [Lipschitz] simulation of Lipschitz Lipschitz exponent based on MATLAB
- Advanced query of MySQL table
- [vuforia] simple logic of image recognition
- py3 redis通用调用
- 常用postgresql数据操作备忘(不定时更新)
- 对于每一个 Provider 实例都会维护多个连接
- UE-插件 ElectronicNodes 5.0.0/4.23-4.27
- Tidb learning
- Project structure of wechat applet
猜你喜欢

【FPGA教程案例27】通过Verilog实现双口RAM乒乓结构

HighTec 新建 AURIX TC37X demo 工程

C语言动态内存开辟和柔性数组

Time frequency diagram classification challenge of intelligent hardware voice control 2.0 (ideas and results, currently top5)

Redis简介

Gin框架原理

Project structure of wechat applet

On the third day of security, iptables prevents nmap scanning and binlog

TCP/IP 协议

手机平台上的用户空间锁概述
随机推荐
【TA-霜狼_may-《百人计划》】美术2.1 DCC工具链与引擎工具链
Static attributes and static methods of class in JS
[Unity] 交互之双击
【TA-霜狼_may-《百人计划》】基础渲染光照介绍(一)
VirtualLab基础实验教程-7.偏振(3)
LeetCode-移除元素
CKS 核心知识点概述
PingCAP Clinic 数据采集说明
Challenges and Countermeasures of deep forgery to national security
Wildfly: how to call EJBs from EJBs located in another application
Policy mode replaces if else
Install go:tools failed to install in vscode
CKA 核心知识点概述
Kubernetes 的监控与告警
OLTP 负载性能优化实践
[TA frost wolf _may - "hundred people plan"] art 2.1 DCC tool chain and engine tool chain
【每日一题】剑指 Offer II 041. 滑动窗口的平均值
Codeforces Round #807 (Div 2.) AB
RK1126实现画中画功能 picture in picture for RK 1126
PyTorch Image Models(timm)库