2. update
update update `表名` set `colnum_name` = value, [`colnum_name`=value, ...] where [条件] #将表中列明为name,id-1的值改为张三 update `表名` set `name`=’张三' where id =1 #修改多个属性,逗号隔开 update `student` set `name`='John', `email`='23423423@qq.com' where id=1 where条件语句 =, <>, <, > , <=, >=, between...and..., and, or3.delete
delete 语法: 删除指定数据 delete from `表名` where `id`= 1; truncate ’表名' delete与truncate比较 truncate重新设置,自增列,计数器会归零 truncate 不会影响事务4.查找select
//查询student表中所有的内容 select * from student #查询指定字段 select ` `, ` ` from student #查询student表中studentno,studentname中的值并使用别名学号和学生姓名显示 select `studentNo` as 学号, `studentname` as 学生姓名 from student #函数 concat(a, b) select concat('姓名:', studentname) as 新名字 from student #去重查询 select distinct `studentno` from result #查询MySQL版本 select version() #计算算法结果 select 300*3-1 as 计算结果 #查询自增的步长 select @@auto_increment_increment #考生成绩+1 select `studentno`, `studentresult`+1 as '提分后' from result 数据库中的表达式:文本值,列,null,函数,计算表达式,系统变量.... select 表达式 from 表 where条件 运算符(两种写法都可以,一般写英文) and && or || not !
5.模糊查询
#模糊查询 运算符 is null 如果操作符为null返回真 is not null between and a between b and c 若a在b和c之间返回真 like a like b sql匹配,如果a匹配b,则结果为真 in a in (a1, a2, a3,...) 假设a在a1,a2,... 之间,返回真 #查询只有两个字的刘姓学生 select `studentno`, `studentname` from `student` where studentname like '刘%_' #查询名字中间有“嘉”字的同学 select `studentno`, `studentname` from `student` where studentname like '%嘉%' #查询三个字的刘姓同学 select `studentno`, `studentname` from `student` where studentname like '刘__' #查询学号在1001,1002,1003之间的学生 select `studentno`,`studentname` from `student` where studentno in (1001, 1002, 1003) #查询住址在北京的学生 select * from student where address in ('北京朝阳') #查询地址为空的同学 select * from student where address is null; #查询地址不为空的同学 select* from student where address is not null