当前位置:网站首页>Mysql database foundation: views and variables
Mysql database foundation: views and variables
2022-06-30 10:43:00 【Long lasting bangbangjun】
View
1、 meaning
Simply understand that a view is a virtual table , The data for rows and columns comes from the tables used in queries that define views , And it's dynamically generated when using views , Only saved sql Logic , Do not save query results .
- Use scenarios
The same query results are used in multiple places , The query result uses sql The statement is more complex .
2、 View features
1、 favour and put sb. in important position sql sentence
2、 Simplify complex sql operation , You don't have to know its query details
3、 Protection data , Improve safety ( Only provide data that customers want to know )
3、 establish / Modify the view
- grammar
# Mode one :
create view View name
as
Query statement ;
# The following two statements can also be used to modify the view
# Mode two
create or replace view View name
as
Query view ;
# Mode three
alter view View name
as
Query view ;
4、 View view
# Mode one
desc View name ;
# Mode two
show create view View name ;
5、 Delete view
drop view View name 1, View name 2...;
6、 Update the view
Update the data in the view
- grammar
# Insert
insert into View name varlues(' value 1',' value 2',...);
# modify
update View name set Name =' value ',... where Conditions
;
# Delete
delete from View name where Conditions ;
It should be noted that the view update operation is generally not allowed , Because the update of the view will cause the data in the original table to change
The following types of views cannot be updated
7、 Comparison between view and table
| type | Create keywords for Syntax | Whether it actually takes up physical space |
|---|---|---|
| View | create | Only saved sql Logic , It doesn't take up space |
| surface | create table | Saved data , Occupancy space |
Variable
1、 classification
- System variables
- Global variables
- Session variables
- Custom variable
- User variables
- local variable
2、 System variables
explain
Variables are provided by the system , Not user defined , At the server level .Scope
- Global variables : Every time the server starts, it will assign initial values to all global variables , Valid for all session connections .
- Session variables : Only valid for the current session connection .
grammar
1、 Look at all the system variablesshow global|【session】 variables2、 Look at some of the system variables that meet the criteria
show global|【session】variables like '%char%';3、 View the value of a specified system variable
select @@global|【session】. System variable name4、 Assign a value to a system variable
Mode one :set global|【session】 System variable name = value ;
Mode two :set @@global|【session】. System variable name = value ;
Add : If it is global level , You need to add global, If it's session level , You need to add session, If you do not write, the default is session
3、 Custom variable
- explain :
Variables allow users to define themselves , Not defined by the system - Use steps :
(1) Statement (2) assignment (3) Use ( see 、 Compare 、 Operations, etc )
3.1 User variables
- Scope : The pin is valid for the current session connection , Can be applied anywhere , That is to say begin end Inside or begin end outside
- Declare and initialize
Mode one :
set @ User variable name = value ;
Mode two :set @ User variable name := value ;
Mode three :select @ User variable name := value ;
- assignment ( Update the value of the user variable )
Mode one : adopt set or select
Mode one :
set @ User variable name = value ;
Mode two :set @ User variable name := value ;
Mode three :select @ User variable name := value ;
Mode two : adopt select into
select Field into Variable name from surface ;
# for example : take count(*) The obtained value is assigned to @count Go to variables
select count(*) into @count;
- Use ( Look at the value of the user variable )
select @ User variable name ;
3.2 local variable
Scope : Just defining it begin end Effective in , Apply to begin end The first sentence of
- Statement
Mode one :
declare Variable name type ;
Mode two :declare Variable name type default value ;
- assignment
Mode one :
Mode one :
set Local variable name = value ;
Mode two :set Local variable name := value ;
Mode three :select Local variable name := value ;
Mode two : adopt select into
select Field into Local variable name from surface ;
- Use
select Local variable name ;
边栏推荐
- Implementation of iterative method for linear equations
- Foster design method
- 技能梳理[email protected]+adxl345+电机震动+串口输出
- Gd32 RT thread DAC driver function
- 历史上的今天:微软收购 PowerPoint 开发商;SGI 和 MIPS 合并
- 再测云原生数据库性能:PolarDB依旧最强,TDSQL-C、GaussDB变化不大
- Gd32 RT thread RTC driver function
- MySQL log management, backup and recovery of databases (2)
- The AOV function of R language was used for repeated measures ANOVA (one intra group factor and one inter group factor) and interaction Plot function and boxplot to visualize the interaction
- Yixian e - commerce publie un rapport trimestriel: adhérer à la R & D et à l’investissement de la marque, réaliser un développement durable et de haute qualité
猜你喜欢

Viewing technological changes through Huawei Corps (V): smart Park

Musk has more than 100 million twitter fans, but he has been lost online for a week

IPhone address book import into Excel

Auto SEG loss: automatic loss function design

ArcGIS Pro + PS 矢量化用地规划图
[email protected]體感機械臂"/>技能梳理[email protected]體感機械臂
![[deep learning] common methods for deep learning to detect small targets](/img/c6/8f0549864992a1554397bad16dad4d.jpg)
[deep learning] common methods for deep learning to detect small targets

Overview of currency

Voir le changement technologique à travers la Légion Huawei (5): Smart Park

从0使用keil5软件仿真调试GD32F305
随机推荐
吴恩达2022机器学习专项课测评来了!
GD32 RT-Thread flash驱动函数
"Hackers and painters" -- why not be stupid
Android 开发面试真题进阶版(附答案解析)
About Library (function library), dynamic library and static library
【Rust日报】2021-01-23 几个新库发布
Arm新CPU性能提升22%,最高可组合12核,GPU首配硬件光追,网友:跟苹果的差距越来越大了...
技能梳理[email protected]+阿里云+nbiot+dht11+bh1750+土壤湿度传感器+oled
【Rust每周一库】num-bigint - 大整数
[rust weekly database] num bigint - large integer
Leetcode question brushing (II) -- sorting (go Implementation)
Es common curl finishing
Agile Development: super easy to use bucket estimation system
[rust daily] the first rust monthly magazine on January 22, 2021 invites everyone to participate
Overview of currency
Compétences Comb 27 @ Body sense Manipulator
Ant s19xp appeared in 140t, why is it called the computing power ceiling by the world
Gd32 RT thread PWM drive function
程序员需知的 59 个网站
如何解决跨域
