当前位置:网站首页>Mysql database foundation
Mysql database foundation
2022-07-02 12:08:00 【The dishes are not right】
Catalog
🥬 Common data types
1、int: plastic
2、double(m,d)
decimal(m,d): Floating point type (m Specify the length ,d It means the number of decimal places )
3、varchar(size): String type
4、timestamp: The date type
🥬 Basic operation of database
No matter what statement is executed , Add... At the end of the sentence ;( A semicolon ).
1、 Create database
create database Database name ;
2、 Show current database
show databases;
3、 Delete database
drop database Database name ;
4、 Using a database
use Database name ;
5、 Create table
create table Table name ;
6、 View table structure
desc Table name ;
7、 insert data
insert into Table name values( Write... Against the type of the column );
8、 Look for statements
Full column lookup
select * from Table name ;
Specified column query
select Name , Name …… from Table name ;
Specifies that the query field is an expression ( In the query , Perform some operations at the same time )
select Name +(-*/) Name from Table name ;
Specify alias for query field
select Name …… as Alias from Table name ;
De duplication of query results
select distinct Name from Table name ;
Sort the query results
select * from Table name order by Name asc/desc;// Ascending / Descending
Paging query
select * from Table name limit n;// from 0 Start , Screening n Bar result
select * from Table name limit n offset s;// from s Start , Screening n Bar result
Conditions of the query
select Name from Table name where Conditions ;
Common operators :
and,or,not And or not (and Priority ratio or high )
>,>=,<,<= Greater than , Greater than or equal to ……
= More equal , No comparison NULL
<=> More equal , Compare NULL
!=,<> It's not equal to
between a and b Range match , In the closed zone [a,b] Within the scope of
in (option, ...) If it is option Any one of , return TRUE(1)
is NULL yes NULL
like Fuzzy matching ,% Denotes any number of ( Include 0 individual ) Any character ;_ Represents any character
The results of the above search are all one " A temporary table ", The tables of the database are all on the hard disk , The query result temporary table here , Not on the hard drive , It's in memory , With the output , The data is released . So the above operations are all temporary table operations , No impact on raw data .
When user input sql after , The client will put this sql Packaged as a network request , To the server , After the server receives the request , Will operate the hard disk , Read data from the hard disk and package the data into a response . After the client receives the response data , The response result will be temporarily saved in memory and output on the display ( Print on standard output ) As the printing is completed , The result data saved in the client memory is also released .
9、 Modify the statement
update Table name set Name = value …… where Conditions ;
10、 Delete statements
delete from Table name where Conditions ;
What is modified here is the original data .
Illustrate with examples :
Create database :
Show current database :
Create a student Table of ( When you need to manipulate a table in a database , You need to use the database first ):
View table structure :
Insert and view :
insert When inserting , You can insert only one column or several columns . At this time, the other columns will adopt the default value
Multiple columns can be inserted at one time , use (), separate
If a certain type is datetime, There are three ways to insert
lookup :
Specify column lookup
Specifies that the query field is an expression
Specify alias for query field
De duplication of query results
Sort the query results
Ascending
Descending
If there is NULL value , Default NULL The value is the minimum
Conditions of the query
% Match any number of ( Include 0 individual ) character , You can match the name starting with any piece
_ Match a strict arbitrary character , One _ Can match a character .
Paging query
Check the results of the top three
modify :
Change Zhang San's Chinese score to 80
Revise everyone's Chinese grades
Add the Chinese scores of everyone in the top three of the total scores 10
Delete :
🥬 Constraint type
2、unique--- Ensure that each row of a column must have a unique value .
3、default--- Specifies the default value when the column is not assigned a value .
When a default value is specified , When the column is not assigned a value , The default value of this column is the specified default value .
4、primary key( The most important constraint )not null and unique The combination of . Make sure that a column ( Or a combination of two or more columns ) There is a unique identification , Helps to find a specific record in a table more easily and quickly . Primary key constraint , Equivalent to the unique identification of data . For a table , Only one column can be specified as the primary key .
Since the primary key primary key auto_increment, When the auto increment primary key is set , The record inserted at this time , You can not specify the value of self incrementing primary key ( Use it directly null To express ) , hand mysql Just distribute it yourself .
5、foreign key --- Ensure referential integrity of data in one table matching values in another table .
Also known as foreign key constraints , Describes the relationship between two columns of two tables " Dependency relationship ” The child table depends on the parent table ( The child table is referenced from the parent table ) The corresponding records in the child table must exist in the parent table .
for instance : Create a class table and student table as follows , Every student should belong to a specific class , This class must exist first , Here the student table depends on the class table , Just call the student list ” Sub table “, The class schedule is called ” Parent table “.
This situation can be described by foreign key constraints .
Foreign key constraints , Describes the relationship between two columns of two tables " Dependency relationship ", The child table depends on the parent table ( The child table is referenced from the parent table ) The corresponding records in the child table must exist in the parent table , The classes in the class table are only 1,2,3, At this time, I insert a class as 10, There will be errors , Insert the failure .
Insert some classes in the class table and they will be inserted successfully .
Foreign key constraints also constrain the parent table , When a record in the parent table is dependent on the child table , At this point, any attempt to delete the modification will fail .
🥬 Summary
That's what we have today , If you have any questions, you can leave a message in the comment area
边栏推荐
猜你喜欢
二分刷题记录(洛谷题单)区间的甄别
Small guide for rapid formation of manipulator (VII): description method of position and posture of manipulator
HR wonderful dividing line
使用Sqoop把ADS层数据导出到MySQL
基于Arduino和ESP8266的连接手机热点实验(成功)
Map和Set
HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
PyTorch nn.RNN 参数全解析
自然语言处理系列(三)——LSTM
H5, add a mask layer to the page, which is similar to clicking the upper right corner to open it in the browser
随机推荐
Natural language processing series (I) -- RNN Foundation
Log4j2
Some problems encountered in introducing lvgl into esp32 Arduino
CDH存在隐患 : 该角色的进程使用的交换内存为xx兆字节。警告阈值:200字节
Yygh-10-wechat payment
PyTorch中repeat、tile与repeat_interleave的区别
Maximum profit of jz63 shares
Small guide for rapid formation of manipulator (VII): description method of position and posture of manipulator
高德地图测试用例
5g era, learning audio and video development, a super hot audio and video advanced development and learning classic
Dynamic memory (advanced 4)
Leetcode209 subarray with the smallest length
深入理解PyTorch中的nn.Embedding
K-Means Clustering Visualization in R: Step By Step Guide
小程序链接生成
(C语言)输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
Deep understanding of NN in pytorch Embedding
Leetcode14 longest public prefix
FastDateFormat为什么线程安全
基于Arduino和ESP8266的Blink代码运行成功(包含错误分析)