当前位置:网站首页>MySQL view concept, create view, view, modify view, delete view
MySQL view concept, create view, view, modify view, delete view
2022-07-02 01:46:00 【No development, no work】
List of articles
1 Concept of view
- View is a virtual table , There is no data in itself , Takes up very little memory space , It is SQL An important concept in .
- Views are built on existing tables , The tables on which the view is built are called Base watch .
- The creation and deletion of views only affect the view itself , It does not affect the corresponding base table . But when the data in the view is added 、 When deleting and modifying operations , The data in the data table will change accordingly , vice versa .
- The statement that provides data content to the view is SELECT sentence , A view can be understood as Stored up SELECT sentence .
- In the database , The view does not save data , The data is really saved in the data table . When adding data to the view 、 When deleting and modifying operations , The data in the data table will change accordingly ; vice versa .
- View , Is another form of providing users with base table data . Usually , Databases for small projects may not use views , But on big projects , And when the data table is complex , The value of view is highlighted , It can help us put the result set of frequent queries into the virtual table , Improve efficiency . It is very convenient to understand and use .
2 Create view
2.1 grammar
- stay CREATE VIEW Insert subquery in statement
CREATE [OR REPLACE]
[ALGORITHM = {
UNDEFINED | MERGE | TEMPTABLE}]
VIEW View name [{ Field list }]
AS Query statement
[WITH [CASCADED|LOCAL] CHECK OPTION]
- Lite version
CREATE VIEW View name [( Field list )]
AS Query statement
2.2 Name the field
-- Mode one
CREATE VIEW emp_view AS SELECT
employee_id emp_id,-- The column name of the view is consistent with the alias
last_name lname,
salary
FROM
employees;
-- Mode two
-- The name should correspond to the query field one by one
CREATE VIEW emp_view2 ( emp_id, lname, money ) AS SELECT
employee_id,
last_name,
salary
FROM
employees;
3 View view
-- View tables and views
SHOW TABLES;
-- View view structure
DESC emp_view2;
-- View the attribute information of the view
SHOW TABLE STATUS LIKE 'emp_view2';
-- View the detailed definition information of the view
SHOW CREATE VIEW emp_view2;
4 Modify the view
-- Create a view to modify
CREATE VIEW emp_view AS SELECT
employee_id emp_id,
last_name lname,
salary
FROM
employees;
-- Modification method 1
CREATE OR REPLACE VIEW emp_view AS SELECT
employee_id,
last_name,
salary,
email
FROM
employees
WHERE
salary > 7000;
-- Modification method 2
ALTER VIEW emp_view AS SELECT
employee_id emp_id,
last_name lname,
salary
FROM
employees;
5 Delete view
-- Delete view
DROP VIEW IF EXISTS emp_view;
DROP VIEW IF EXISTS emp_view,emp_view2;
边栏推荐
- NeRV: Neural Reflectance and Visibility Fields for Relighting and View Synthesis
- Android high frequency network interview topic must know and be able to compare Android development environment
- 并发编程的三大核心问题
- 跨域?同源?一次搞懂什么是跨域
- MATLAB realizes voice signal resampling and normalization, and plays the comparison effect
- SAP ui5 beginner tutorial 20 - explanation of expression binding usage of SAP ui5
- 6-2漏洞利用-ftp不可避免的问题
- 6-3 vulnerability exploitation SSH environment construction
- Learn about servlets
- Ubuntu20.04 PostgreSQL 14 installation configuration record
猜你喜欢
Feature extraction and detection 16 brisk feature detection and matching
Self drawing of menu items and CListBox items
迁移云计算工作负载的四个基本策略
MPLS experiment operation
浅浅了解Servlet
Should enterprises choose server free computing?
[disease detection] realize lung cancer detection system based on BP neural network, including GUI interface
Learn basic K-line diagram knowledge in three minutes
Another programmer "deleted the library and ran away", deleted the code of the retail platform, and was sentenced to 10 months
Convolutional neural network (including code and corresponding diagram)
随机推荐
Introduction to ffmpeg Lib
Four basic strategies for migrating cloud computing workloads
10 minutes to get started quickly composition API (setup syntax sugar writing method)
Learn about servlets
卷積神經網絡(包含代碼與相應圖解)
uTools
[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production
城市选择器组件实现原理
技术大佬准备就绪,话题C位由你决定
matlab 实现语音信号重采样和归一化,并播放比对效果
Electronic Association C language level 1 33, odd even number judgment
MATLAB realizes voice signal resampling and normalization, and plays the comparison effect
np.where 和 torch.where 用法
卷积神经网络(包含代码与相应图解)
matlab 使用 audiorecorder、recordblocking录制声音,play 播放声音,audiowrite 保存声音
6-3漏洞利用-SSH环境搭建
PR second training
Réseau neuronal convolutif (y compris le Code et l'illustration correspondante)
Using tabbar in wechat applet
Matlab uses audiorecorder and recordblocking to record sound, play to play sound, and audiobook to save sound