当前位置:网站首页>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

边栏推荐
- CDA数据分析——AARRR增长模型的介绍、使用
- How to Add P-Values onto Horizontal GGPLOTS
- Natural language processing series (III) -- LSTM
- (C language) octal conversion decimal
- mysql表的增删改查(进阶)
- H5,为页面添加遮罩层,实现类似于点击右上角在浏览器中打开
- [untitled] how to mount a hard disk in armbian
- PyTorch搭建LSTM实现服装分类(FashionMNIST)
- HR wonderful dividing line
- Full link voltage measurement
猜你喜欢

Data analysis - Matplotlib sample code

Deep understanding of NN in pytorch Embedding

(C language) 3 small Codes: 1+2+3+ · · +100=? And judge whether a year is a leap year or a normal year? And calculate the circumference and area of the circle?

基于Arduino和ESP8266的连接手机热点实验(成功)

二分刷题记录(洛谷题单)区间的甄别

ESP32 Arduino 引入LVGL 碰到的一些问题

XSS labs master shooting range environment construction and 1-6 problem solving ideas

Jenkins voucher management

GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT

Dynamic debugging of multi file program x32dbg
随机推荐
Take you ten days to easily finish the finale of go micro services (distributed transactions)
Gaode map test case
Orb-slam2 data sharing and transmission between different threads
uniapp uni-list-item @click,uniapp uni-list-item带参数跳转
Codeforces 771 div2 B (no one FST, refers to himself)
倍增 LCA(最近公共祖先)
BEAUTIFUL GGPLOT VENN DIAGRAM WITH R
行業的分析
甜心教主:王心凌
Dynamic memory (advanced 4)
Codeforces 771-div2 C (trouble, permutation is not very good)
测试左移和右移
Data analysis - Matplotlib sample code
Time format display
Applet link generation
Leetcode122 买卖股票的最佳时机 II
Log4j2
Depth filter of SvO2 series
mysql表的增删改查(进阶)
Leetcode14 longest public prefix