当前位置:网站首页>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. !
边栏推荐
- Unity小技巧 - 绘制瞄准准心
- C WinForm series button easy to use
- Models used in data warehouse modeling and layered introduction
- Wechat applet obtains mobile number
- Summary of study notes for 2022 soft exam information security engineer preparation
- [reverse] repair IAT and close ASLR after shelling
- 05 personal R & D products and promotion - data synchronization tool
- [introduction to MySQL] the first sentence · first time in the "database" Mainland
- Uipath browser performs actions in the new tab
- PyTorch 提取中间层特征?
猜你喜欢
FlutterWeb浏览器刷新后无法回退的解决方案
CTF reverse entry question - dice
Concept and basic knowledge of network layering
Pyspark operator processing spatial data full parsing (5): how to use spatial operation interface in pyspark
Solr appears write Lock, solrexception: could not get leader props in the log
Deploy flask project based on LNMP
Huawei certified cloud computing hica
酷雷曼多种AI数字人形象,打造科技感VR虚拟展厅
Basic configuration and use of spark
pip install pyodbc : ERROR: Command errored out with exit status 1
随机推荐
Vscode matches and replaces the brackets
Interpretation of Flink source code (II): Interpretation of jobgraph source code
04个人研发的产品及推广-数据推送工具
Zen integration nails, bugs, needs, etc. are reminded by nails
[ASM] introduction and use of bytecode operation classwriter class
C version selenium operation chrome full screen mode display (F11)
Guidelines for preparing for the 2022 soft exam information security engineer exam
[translation] principle analysis of X Window Manager (I)
Pyspark operator processing spatial data full parsing (4): let's talk about spatial operations first
Reppoints: advanced order of deformable convolution
Spark calculation operator and some small details in liunx
Unity particle special effects series - treasure chest of shining stars
Remote code execution penetration test - B module test
Automatic operation and maintenance sharp weapon ansible Foundation
connection reset by peer
Grafana 9 is officially released, which is easier to use and more cool!
How to use scroll bars to dynamically adjust parameters in opencv
mysql高级(索引,视图,存储过程,函数,修改密码)
基本磁盘与动态磁盘 RAID磁盘冗余阵列区分
微信小程序获取手机号