当前位置:网站首页>MySQL view
MySQL view
2022-07-05 12:12:00 【ziyi813】
MySQL View
Introduce
View view It's a virtual table , It's not real , Its essence is based on SQL Statement to get a dynamic data set , And name it , Users only need to use the view name to get the result set , And you can use it as a table .
The database only stores the definition of the view , There is no data stored in view , These data are still put in the original data table .
 When using views to query data , The database system will take the corresponding data from the original data table . therefore , The data in the view depends on the data in the source data table , Source data change , The data displayed in the view will also change .
effect
Simplify the code , Reusable queries can be closed into views for reuse , At the same time, it can make complex queries easy to understand and use
Security reasons , If there are a lot of data in a table , A lot of information doesn't want to be seen by everyone , You can use the view , Such as : There is a table that shows only names and some insensitive fields open to others , ID card and salary are not displayed , It can be applied to different users , Set different views .
View creation
Grammar format :
create [or replace] [algorithm = {undefind | mgerge | templtable } }]
view view_name [ {column_list} ]
as select_statement
[with [cascaded | local ] check option ]
Parameter description :
- algorithm: optional , Algorithm for view selection
- view_name: Represents the name of the view to be created
- column_list: optional , Specifies the noun for each attribute in the view , By default, it is the same as select The properties of the query in the statement are the same
- select_statement: Represents a complete query statement , Import the query record into the view
- [width [cascaded | local ] check option ]: optional , It means that updating the view should be within the permission range of the view
The operation sample :
-- Create view 1
create or replace view view1_emp
as
select emp_name from emp;

-- Query all tables , Differentiate view
select full tables;
Modify the view
Modifying a view means modifying the definition of a table that already exists in the database . When some fields in this table change , You can modify the view to keep it consistent with this table .MySQL Pass through CREATE REPLACE VIEW Statement and ALTER VIEW Statement to modify the view .
Format :
alter view View name as select sentence
Example :
-- Modify the view
alter view view1_emp
AS
select emp_name, salary from emp;
Update the view
Some views are updatable . in other words , Can be in UPDATE、DELETE perhaps INTER And so on , In a more basic form ( Data source table ) The content of . For updatable views , Rows in the view and rows in the base table must have a one-to-one relationship , If the view contains any of the following structures , So it's not updatable .
- Aggregate functions (SUM(), MIN(), MAX(), AVG(), COUNT() etc. )
- DISTINCT
- GROUP BY
- HAVING
- UNION perhaps UNION ALL
- JOIN
- FORM Non updatable view in Clause
- WHERE Subquery in Clause , quote FROM Table in clause
- Reference text values only
Although the data can be updated in the view , But there are a lot of restrictions , In general , It's best to use the view as a virtual table for querying data , Instead of updating data through views . because , When using views to update data , If the limitation of updating data is not fully considered , Data update may fail .
Other operations of view
Rename view
-- Rename view
rename table view1_emp to myview1;
Delete view
-- Delete view
drop view if exists myview1
边栏推荐
- 【主流Nivida显卡深度学习/强化学习/AI算力汇总】
- 跨平台(32bit和64bit)的 printf 格式符 %lld 输出64位的解决方式
- 【L1、L2、smooth L1三类损失函数】
- HiEngine:可媲美本地的云原生内存数据库引擎
- [cloud native | kubernetes] actual battle of ingress case (13)
- Network five whip
- 一款新型的智能家居WiFi选择方案——SimpleWiFi在无线智能家居中的应用
- Riddle 1
- ACID事务理论
- Complete activity switching according to sliding
猜你喜欢

Matlab imoverlay function (burn binary mask into two-dimensional image)

查看rancher中debug端口信息,并做IDEA Remote Jvm Debug

Linux安装部署LAMP(Apache+MySQL+PHP)

多表操作-自关联查询

Error modulenotfounderror: no module named 'cv2 aruco‘

Understand kotlin from the perspective of an architect

Four operations and derivative operations of MATLAB polynomials
![[cloud native | kubernetes] actual battle of ingress case (13)](/img/1a/9404f6dcedd15827fa45f8f6f4c093.png)
[cloud native | kubernetes] actual battle of ingress case (13)

pytorch-权重衰退(weight decay)和丢弃法(dropout)

【主流Nivida显卡深度学习/强化学习/AI算力汇总】
随机推荐
跨平台(32bit和64bit)的 printf 格式符 %lld 输出64位的解决方式
[pytorch modifies the pre training model: there is little difference between the measured loading pre training model and the random initialization of the model]
【主流Nivida显卡深度学习/强化学习/AI算力汇总】
Embedded software architecture design - message interaction
全网最全的新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀
Swift - enables textview to be highly adaptive
[yolov3 loss function]
[yolov5.yaml parsing]
Principle of persistence mechanism of redis
Simply solve the problem that the node in the redis cluster cannot read data (error) moved
HiEngine:可媲美本地的云原生内存数据库引擎
Matlab boundarymask function (find the boundary of the divided area)
信息服务器怎么恢复,服务器数据恢复怎么弄[通俗易懂]
[configuration method of win11 multi-user simultaneous login remote desktop]
Pytorch softmax regression
Matlab imoverlay function (burn binary mask into two-dimensional image)
Troubleshooting of high memory usage of redis in a production environment
Halcon 模板匹配实战代码(一)
强化学习-学习笔记3 | 策略学习
liunx禁ping 详解traceroute的不同用法