SQL语言

数据表操作

创建表

create table 表名{
     字段名 类型 约束,
     字段名 类型 约束,
     .....
}

删除表

格式一:drop table 表名
格式二:drop table if exists 表名  //先检验是否有这个表

数据操作

添加数据

格式一:insert into 表名 values(...)  //括号里填一条数据的所有字段信息
格式二:insert into 表名(字段1,字段2,...) values(值1,值2,...) 

修改数据

update 表名 set 列1=值1,列2=值2... where 条件

删除数据

delete from 表名 where 条件

查询数据

查询所有信息

select * from 表名

查询指定字段

select 列1,列2,... from 表名

消除重复行 distinct

select distinct 列1 from 表名
例:select distinct age from students

条件查询

使用where子句对数据表进行筛选

select * from 表名 where 条件
例:select * from students where age=18
比较运算符:

等于:=,大于:>,大于等于:>=,小于:<,小于等于:<=,不等于:!=或<>

逻辑运算符:

and,or,not

select * from students where age=18 and address='北京' //查询年龄是18岁和地址是北京的学生
select * from students where age=18 or address='北京' //查询年龄是18岁或者地址是北京的学生
select * from students where not age=18 //查询年龄不是18岁的学生
模糊查询:
  • like
  • %表示任意多个字符
  • _表示一个任意字符
select * from students where name like '张%' //查询姓张的学生
select * from students where name like '_徐坤' //查询名字后两个字叫徐坤的学生 
范围查询:

in:表示在一个非连续的范围

select * from students where age in (17,18,20,28)

between...and... :表示在一个连续的范围

select * from students where age between 18 and 20 //查询年龄为18到20岁的学生
空判断:

注意:null跟' '是不同的

判断空 is null

判断不为空 is not null

select * from students where address is null
select * from students where address is not null

排序:

升序:asc(不填默认是升序)

降序:desc

select * from students order by age asc //可以不写asc也行,默认是升序
select * from students order by age desc //降序

 

转载于:https://www.cnblogs.com/Jhuahua/p/11523100.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值