Add, delete, check and modify MySQL tables (suitable for preliminary learning)

Series Article Directory

The previous blog mainly introduced the basic operations and data types of MySQL. For details, please read inside: The previous blog: Xiaobai learns MySQL

Insert picture description here



Preface

1. CRUD?

CRUD: Create, Retrieve, Update, Delete are
actually abbreviations for adding, deleting, checking and modifying, but in order for us to enter the company to communicate more conveniently in the future, we still need to understand this abbreviation.

Second, the addition, deletion, and modification of MySQL

1. Create

Mainly divided into "single row insert + full column insert" and "multiple row insert + full column insert"
Insert picture description here

Single row insert + full column insert : each column of the table must be inserted in order, and none is null, generally only used when inserting less data;
Insert picture description here

Multi-row insert + full-column insert : You can quickly choose to insert multiple columns of data, without having to insert each column, which is convenient and time-saving.
Insert picture description here

2. Delete (Delecte)

Insert picture description here
1. Delete according to the conditions
Insert picture description here
2. Delete all data of the entire table:
Insert picture description here

3. Query (Retrieve)

Insert picture description here
1. Full column query
Insert picture description here

2. Specify column query
Insert picture description here

3. The query field is an expression
Insert picture description here

4. Alias: In the table set of the query result, alias=table name.
Insert picture description here
In this example, the sum of Chinese, Mathematics, and English scores is divided into aliases. Be sure to remember this format.
Insert picture description here

5. Deduplication: DISTINCT
This example is to deduplicate the specified column math column to remove duplicate values.
Insert picture description here

6. Sorting: ORDER BY
Insert picture description here
(1) For queries without an ORDER BY clause, the return order is undefined;
(2) NULL data sorting is regarded as smaller than any value, ascending order appears at the top, and descending order appears at the bottom Below; the basic format is as follows:
Insert picture description here

(3) Sort using expressions and aliases
Insert picture description here

(4) Multiple fields can be sorted, and the priority of sorting is determined by the order of writing (the default order is ascending)
Insert picture description here

7. Condition query: WHERE

  1. WHERE conditions can use expressions, but not aliases;
  2. AND has a higher priority than OR. When used at the same time, you need to use parentheses () to wrap the priority execution part;

Here are some commonly used operators:

Operator Description
between A and B A<=value<=B, then return true
in(a,b,c,d…) If it is any of the parentheses, it returns true
is null Is null
is not null Not null
like Fuzzy matching,% means any number (including 0) characters; _ means any character
>,>=,<,<=,
= Null is not safe, for example, the result of null=null is still null
<=> Null safety, such as null<=>null, the result is still null
!=,<> Are not equal to

Logical operator:
and or not
here is just one example, fuzzy matching:
Insert picture description here

8. Paging query:
Insert picture description here
OFFSET in the third method of LIMIT is the offset, starting from S, and filtering n results.

4. Update

Insert picture description here
Insert picture description here


to sum up

1. For students who are just starting to learn MySQL, the operation of the table that is just starting to learn is not too difficult. They are all single table operations, mainly conditional query statements. When there are multiple statements querying together, clarify the logic , Don’t forget which condition;
2. You need to practice more . For some query sentences, after you write them, you have to experiment by yourself to know whether the sentences you wrote are correct.

Guess you like

Origin blog.csdn.net/m0_46551861/article/details/109324244