数据库-----表的增删查改(数据库基础)

一.新增

1.单行数据全列插入

insert into 表名 values(数据1,数据2...);

2.多行数据+指定列插入

insert into 表名(指定列1,指定列2...) values(数据1,数据2);

二.查询

1.全列查询:

select * from 表名;

2.指定列查询:

select 指定列1,指定列2 from 表名;

3.查询字段为表达式:

select id,name,math + 10 from 表名;

4.别名:

select id,name 姓名,math + chinese 总分 from 表名;

5.去重:distinct

select distinct math from  表名;

6.排序:order by

desc------为降序
asc-------为升序(默认)
select name from student order by  qq_mail desc;

7.条件查询:where

1.基本查询
select name from student where math > 60;
2.andor
select name from student where math > 60 and chinese > 70;
3.范围查询
   1.between...and...
	select name from student where math between 60 and 70;  
   2.in
   select name from student where math in(60,70);
4.模糊查询:like
	--- % 匹配多个字符
	--- _ 匹配一个字符
select name from student where name like '张%';
5.NULL查询:
select name from student where qq_mail is NULL;

8.分页查询:

------从s到n页
select name from student where math > 60 limit n offset s;

三.修改:update

update 表名 set math = 80 where name = '张三';

四.删除:delete

delete from 表名 where name = '张三';

你可能感兴趣的:(数据库-----表的增删查改(数据库基础))