当前位置:网站首页>MySQL addition, deletion, query and modification (primary level)

MySQL addition, deletion, query and modification (primary level)

2022-06-26 03:29:00 Acquaintance-

MySQL Add, delete, check and modify the primary level

stay MySQL The annotation method in

We can use – perhaps ## stay MySQL Implementation notes in

1. insert data

1.1 Single line input + Insert all columns

– Insert a record ,value_list The number must be consistent with the number and order of the columns that define the table
insert into Table name values( data , data …)
 Insert picture description here

1.2 Multi row data + Specify column insertion

– Insert two records ,value_list The quantity must be consistent with the number and order of the specified columns
Suppose our student Table has id name and score
insert into student(id,name) values (1,‘ Xiao Wang ’),(2,‘ petty thief ’)

 Insert picture description here

3. Inquire about

3.1 Full column query

select * from Table name
 Insert picture description here

View all table data contents ( * The wildcard , Just use * Instead of column names, you can query all columns ) This operation is dangerous , For example, the amount of data is too large
1. Memory full , Cause crash
2.MySQL The server will read the hard disk crazily , Full hard disk IO bandwidth , then MYSQL The server's return to the client will occupy the full network bandwidth )

3.2 Specified column query

select Name , Name from Table name
 Insert picture description here

3.3 The query field is an expression

Form like :

– The expression does not contain fields
select id, name, 10 from student;
– The expression contains a field
select id, name, english + 10 from student;
– The expression contains multiple fields
select id, name, chinese + math + english from student;
 Insert picture description here
 Insert picture description here

3.4 Alias (as)

Name [as] Alias (as It can be omitted )
Such as
– Result set , The column name of the header = Alias
select id, name, chinese + math + english [as] Total score from student;

 Insert picture description here

3.5 duplicate removal (distinct)

When there are duplicates in the data , We can go through distinct To get a result after weight removal
select distinct Name from Table name
 Insert picture description here

3.6 Sort (order by)

Sorting by a benchmark

select Name (*)… from Table name order by Name asc( Ascending )/desc( Descending ) If you omit and do not write, it is the default ascending order , If there is... In the record NULL,NULL Think it's the smallest It is to sort by a certain column among many columns
 Insert picture description here

Sorting by multiple benchmark values

select Name (*)… from Table name order by Name … asc( Ascending )/desc( Descending ) That is to say, in a certain number of columns ( Priority exists ) Sort by benchmark
 Insert picture description here

3.7 Conditions of the query (where)

1. Comparison operator

Operator explain
>, >=, <, <= Greater than , Greater than or equal to , Less than , Less than or equal to
= be equal to ,NULL unsafe , for example NULL = NULL The result is NULL
<=> be equal to , NULL Security , for example NULL <=> NULL The result is TRUE(1)
!=, <> It's not equal to
between a0 and a1 Range match , [a0, a1], If a0 <= value <= a1, return TRUE(1)
in (option, …) If it is option Any one of , return TRUE(1)
is NULL yes NULL
is not NULL No NULL
like Fuzzy matching . % Denotes any number of ( Include 0 individual ) Any character ; _ Represents any character

2. Logical operators

Operator explain
and Logic and More than one condition must be TRUE(1), The result is TRUE(1)
or Logic or Any one of the conditions is TRUE(1), The result is TRUE(1)
not Logic reverses Condition is TRUE(1), The result is FALSE(0)

4. Paging query (limit)

– from 0 Start , Screening n Bar result
select … from table_name [where …] [order by …] limit n;
 Insert picture description here
– from s Start , Screening n Bar result
select … from table_name [where …] [order by …] limit s, n;
 Insert picture description here
– from s Start , Screening n Bar result , Than where This usage is more specific , It is recommended to use
select … from table_name [where …] [order by …] limit n offset s;
 Insert picture description here

5. modify (Update)

update [ Table name ] set [ Name ] = [ Modified value ], [ Name ] = [ Modified value ] where Clause ;
 Insert picture description here

6. Delete (delete)

delete from [ Table name ] where [ filter ];
 Insert picture description here

原网站

版权声明
本文为[Acquaintance-]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260240496028.html