JAVA single row diary -2020 / 2/8-MySQL-DML

1. Insert (add) data

  1. Assignment to a column
insert into 表名(1,2) values (1,2);
  1. To assign all the columns
insert into 表名 values (1,2,..,值n)

In addition to intthe type of data NULL, other types of data all with ''or ""caused by

2. The data look-up table

  • check sentence
select 
	字段列表
from
	表名列表
where
	条件列表
group by
	分组字段
having
	分组之后的条件
order by
	排序
limit
	分页限定
  • Underlying query
  1. Query multiple fields
select 字段名1,字段名2... from 表名;
select * from 表名;  #查询所有字段
  1. remove duplicates
select distinct 字段n from 表名;  #去除表中字段n中的重复元素
  1. Calculated column
      ● Calcd can use a series of four operations;
      ● nullparticipation calculation, the calculation result are null. It may be used ifnull(表达式1,表达式2), if the expression 1 is null, replacing an expression put expression 1 2
  2. Surnamed
select 字段名1 as 别名 from 表名;
select 字段名1 别名 from 表名;
  • Conditions inquiry
  1. where clause followed by the condition
  2. Operators
Operators Features
>、<、<=、>=、=、<> Greater than, less than, greater than or equal, less, equal, non-
and 或 && versus
or 或 || or
or not! non-
between A and B Between A and B (including A and B)
in (collection) Query data in the collection of the
is null Null query data (can not use = null)
like Fuzzy queries. Placeholders: any single character _any number of characters%

3. Delete the data in the table

  1. To delete an item in the table
delete from 表名 where 条件;

Here Insert Picture Description

  1. Delete all the data in the table
delete from 表名;            逐条删除,执行效率低,不推荐使用
truncate table 表名;         删除表,再新建一个一样的,推荐使用

4. Modify the data in the table

update 表名 set1=1,2=2,3=3,...,列n=值n,where 条件; #不加where条件则表中所有数据都会改变
Published 131 original articles · won praise 1 · views 4435

Guess you like

Origin blog.csdn.net/wangzilong1995/article/details/104212215