第五课
MySQL数据库类型
1.数值型:tinyint、smallint、medinint、int、bigint、floot、double、decinmal;
2.字符串类型:char、varchar、binary、text、enum;
3.日期/日期类型:year、time、datetime、timestoop
MySQL数据库操作一
1.往表里面添加数据(两种方式)
语法:insert into 表名(字段名一,字段名二,……) values (值一,值二,……);
语法:insert into 表名 values(值一,值二,……);
代码例子:
①:insert into a(id,name,……) values (1,'名字',……);
②:insert into a values(1,'名字',……);
2.查询数据
语法:select * from 表名;
3.更改数据
语法:update 表名 set 字段名=想要修改的值 where 条件表达式;
4.清除数据
语法:delete from 表名 where 条件表达式;
5.使用in或not in查询满足条件的数据
语法:select * from 表名 where 字段名 in(条件);
语法:select * from 表名 where 字段名 not in(条件);
MySQL数据库操作二
1.带butween and 的范围查询
语法:select *|字段名 from 表名 指定的字段名字 between 值 and 值
2.带like的字符匹配查询
语法:select *|字段名 from 表名 where 指定字段 like 想要匹配得值
代码例子:
select *|a from apple where name like '需要';
3.带%和__结合like查询
语法:select *|字段名 from 表名 where 指定字段 like 想要匹配的值%
语法:select *|字段名 from 表名 where 指定字段 like __想要匹配的值
4.查询空值
语法:select *|字段名 from 表名 where 指定字段 is null;
5.查询非空值
语法:select *|字段名 from 表名 where 指定字段 is not null;
6.使用and实现多条件查询
语法:select *|字段名 from 表名 where 条件表达式1 and 条件表达式2 (不可以为同个字段名)
7.使用or实现多条件查询
语法:select *|字段名 from 表名 where 条件表达式1 or 条件表达式2(不可以为同个字段名)
8.筛选重复的记录
语法:select distinct 字段名 from 表名;