当前位置:网站首页>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. !
边栏推荐
- MySQL Advanced (index, view, stored procedures, functions, Change password)
- 2021-03-22 "display login screen during recovery" can't be canceled. The appearance of lock screen interface leads to the solution that the remotely connected virtual machine can't work normally
- MySQL advanced (index, view, stored procedure, function, password modification)
- Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
- Spark accumulator and broadcast variables and beginners of sparksql
- Flink parsing (III): memory management
- Integrated development management platform
- Debug and run the first xv6 program
- Summary of Android interview questions of Dachang in 2022 (I) (including answers)
- The solution that flutterweb browser cannot be rolled back after refreshing
猜你喜欢
基于STM32+华为云IOT设计的智能路灯
FlutterWeb浏览器刷新后无法回退的解决方案
[rapid environment construction] openharmony 10 minute tutorial (cub pie)
[reverse intermediate] eager to try
Pytorch extract middle layer features?
Application service configurator (regular, database backup, file backup, remote backup)
网络分层概念及基本知识
Concept and basic knowledge of network layering
Models used in data warehouse modeling and layered introduction
BearPi-HM_ Nano development environment
随机推荐
Solrcloud related commands
The problem of "syntax error" when uipath executes insert statement is solved
SAP UI5 框架的 manifest.json
sql语句优化,order by desc速度优化
Deploy flask project based on LNMP
[introduction to MySQL] the first sentence · first time in the "database" Mainland
EasyCVR平台通过接口编辑通道出现报错“ID不能为空”,是什么原因?
【MySQL入门】第三话 · MySQL中常见的数据类型
The art of Engineering (3): do not rely on each other between functions of code robustness
VR全景婚礼,帮助新人记录浪漫且美好的场景
基于LNMP部署flask项目
Detailed explanation of data types of MySQL columns
Debug xv6
OpenCV中如何使用滚动条动态调整参数
Total / statistics function of MySQL
Binary search strategy
Wordcloud colormap color set and custom colors
Application service configurator (regular, database backup, file backup, remote backup)
遠程代碼執行滲透測試——B模塊測試
全网最全tcpdump和Wireshark抓包实践