当前位置:网站首页>Easy introduction to SQL (1): addition, deletion, modification and simple query
Easy introduction to SQL (1): addition, deletion, modification and simple query
2022-07-06 17:45:00 【Data digger】
The authors introduce
Whale song
E-commerce industry data analyst
Provide data consulting services for head brands
Keen to learn and share
“ DataMan creators Alliance ” member
Write in the pen SQL In series , I suddenly feel a little confused , Because in a sense SQL It's a stranger I'm familiar with . Familiar because I and SQL We met very early , Looking back on the whole process , We have experienced shallow acquaintance , Long forgotten in the Jianghu , Then there was a brief reunion , Then separation , Up to now, I once again fell under her pomegranate skirt .
Strangeness is because , Just like the process mentioned above , Many belong to me and SQL Because of the separation, my memories become light . This feeling is wonderful , But I'm glad that I finally understand SQL Position in my heart .

You may want to ask me , How to determine SQL Position in my heart ? My answer is , Golden Circle thinking principle . Whether it's work or daily life , Rather than asking yourself why , We prefer to be guided by brain inertia , Take action first . And often many things come to the end , You will find that it was wrong from the beginning .
Used to be in school ,SQL It's just a course on the curriculum , Step into society ,SQL It's just a necessary tool for work , I have never thought deeply , Why should I choose SQL?SQL What does it mean to me .
SQL He is a good comrade in arms for data analysis , No, SQL, Maybe we face the database , I can't wait to sigh ;
SQL It's a high-level nonprocedural programming language , Master it , We can have one more mode of thinking ;
SQL It is also the stepping stone and chip for our job search and salary increase , It may help you to take another step .
Now that you know SQL Importance to me , So in order not to feel strange anymore , The next period of time , I'll get to know it again SQL, And record these feelings in written form , Come on ! Start the journey of revisiting ~

01 What is a database ? What is? SQL?
database , As the name suggests, it is a warehouse for storing data , It's like an all inclusive storage box , Only its object is data . In the database , We are more exposed to relational databases , It includes multiple tables and the relationship between them . In the database , Relationship is the matching of data between two tables , For example, foreign keys .
SQL It is a tool for operating database , There are primitive and natural information in the database , And refining and processing these information depends on SQL.
02 How to install the database ?
In the choice of database , Usually preferred Mysql, It has the advantages of fast running speed and low cost . Specific installation , Please refer to the installation courses shared online .
Mysql And its good friends Navicat, They are the relationship between being managed and being managed , The former serves as a database system , The latter is a database management tool . Our daily basic operations on the database are Navicat In the middle of , It is powerful and easy to learn .

03 The creation of a table 、 Delete and update
Under the created database , You can right-click to select 【 new table 】:

Create table , The fields of the table will be set :

See the following for the type selection :

“ No null” If checked, it means that null value is not allowed , If it is not checked, it is allowed to be null .
A table can choose >=1 Column as primary key / Composite primary key , Ensure that each row of the table has identity uniqueness .
Null And empty string (“”) The difference is that empty characters have values and can be operated .
After the field is set , Click on 【 preservation 】, The skeleton of the table has been built , You need to fill in the corresponding data :

The above data is similar to Excel The data entered in the table is the same , You need to input one by one manually .
2. Tables can be deleted : Right click to select the table to delete :

In practice ,【 Delete table 】 Be careful , Delete unrecoverable , Never owe your hand !
3. and Excel equally , The data in the table has been changed , It needs to be updated , You can right-click the table , Update and save directly in the table .
04 Data insertion 、 Delete and update
In addition to adopting similar Excel In addition to data entry , You can also use query statements to insert 、 Delete and update :
Insert into < Table name >(< Name 1>,< Name 2>,…)
Values(< value 1>,< value 2>,…)

When inputting symbols, you can only use English , Remember that once there is an error, first check whether the symbol is in Chinese .
A statement ends , In English semicolon (;) ending , Can't forget .
2. DELETE Statement to delete rows in a table :DELETE FROM The name of the table WHERE Column name = value

3. Update Statement to modify the data in the table :UPDATE The name of the table SET Column name = The new value WHERE Column name = Certain value

05 Simple query
The following covers 3 part :
School The database contains 4 Reports :student、score、course and teacher, Report details and primary key ;
SQL Knowledge point framework : Basic statement 、 notes 、 Operators and fuzzy queries ;
Screenshot of actual operation : Correspond to the knowledge points one by one , Continuously improve from practice .
The following figure shows the current issue SQL The statement involves 4 Reports , Although the form is very small , In fact, the energy is huge , The real business scenario will involve more reports and massive data , The essence of the two is the same , The difference is the amount of data . If you can put 4 The actual operation of the report is smooth , So I'm not afraid to encounter a huge amount of data in the future ~

although SQL Easy to use , But as a database tool , We still have to practice makes perfect . Remember the story of the oil man ? Weng said :“ dedicated , But hand cooked. .” At work , Whether it's Excel、SQL still Python, We all need to practice while laying a solid foundation .

SQL Queries are generally targeted data retrieval , Rarely will you query the whole table , Because the amount of data presented is different from SQL The response speed is proportional , When the amount of data is very large, the response time will be longer , If you really need to see the whole table , It can be used limit Limit the number of rows ;

As In addition to setting the alias of the column , You can also set the alias of the table , Especially when it comes to multi table joins ;

Distinct Remember the placement of , In addition, the use of multiple columns may be ignored ;

Select You can also calculate the value directly ;




Not It's not commonly used , But you can also see in complex sentences , At this time, you should understand the meaning it represents ;

The priority of the operation cannot be mistaken , If it's a little windy , You can put it on the paper first where Write the clause well ;



Fuzzy query is used in many practical business scenarios , It is necessary to clarify what data to extract .


The old saying goes : The fist does not leave the hand , practice singing all the time ,SQL Also practice often !SQLZOO Is a good practice website , It's not important to know , It's good to do it , come on. !
边栏推荐
- Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
- 【ASM】字节码操作 ClassWriter 类介绍与使用
- Wordcloud colormap color set and custom colors
- Error: Publish of Process project to Orchestrator failed. The operation has timed out.
- Binary search strategy
- Reppoints: advanced order of deformable convolution
- connection reset by peer
- [reverse] repair IAT and close ASLR after shelling
- Flink parsing (III): memory management
- [elastic] elastic lacks xpack and cannot create template unknown setting index lifecycle. name index. lifecycle. rollover_ alias
猜你喜欢

CTF reverse entry question - dice

PySpark算子处理空间数据全解析(4): 先说说空间运算

Concept and basic knowledge of network layering

The solution that flutterweb browser cannot be rolled back after refreshing

【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符

Grafana 9 正式发布,更易用,更酷炫了!
![[translation] principle analysis of X Window Manager (I)](/img/40/6e15e1acebb47061d6e0e4c8ff82ea.jpg)
[translation] principle analysis of X Window Manager (I)

酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅

C version selenium operation chrome full screen mode display (F11)

C WinForm series button easy to use
随机推荐
Summary of Android interview questions of Dachang in 2022 (II) (including answers)
【MySQL入门】第四话 · 和kiko一起探索MySQL中的运算符
C WinForm series button easy to use
How to use scroll bars to dynamically adjust parameters in opencv
【MySQL入门】第三话 · MySQL中常见的数据类型
The art of Engineering (3): do not rely on each other between functions of code robustness
EasyCVR接入设备开启音频后,视频无法正常播放是什么原因?
VR全景婚礼,帮助新人记录浪漫且美好的场景
Virtual machine startup prompt probing EDD (edd=off to disable) error
Summary of Android interview questions of Dachang in 2022 (I) (including answers)
2022年大厂Android面试题汇总(二)(含答案)
CTF reverse entry question - dice
应用服务配置器(定时,数据库备份,文件备份,异地备份)
Flink parsing (V): state and state backend
05个人研发的产品及推广-数据同步工具
How to submit data through post
Spark accumulator and broadcast variables and beginners of sparksql
基于STM32+华为云IOT设计的智能路灯
【Elastic】Elastic缺少xpack无法创建模板 unknown setting index.lifecycle.name index.lifecycle.rollover_alias
07 personal R & D products and promotion - human resources information management system