一、数据类型
数值类型
整型
- bit:设置boolean类型,设置bit
- int :对应 integer
浮点型
- float/daouble
- decimal(总长度,小数位数)
字符串类型
- varchar(size) 普通字符串
- text:大文本
日期类型
- datetime
- timestamp:java.util.Date
二、库的操作
1.创建
create关键字
创建:
![[外链图片转存失败(img-0Y0C1YHV-1569143802309)(en-resource://database/1023:1)][外链图片转存失败(img-h51SdtDP-1569143802315)(en-resource://database/1027:1)]](https://i-blog.csdnimg.cn/blog_migrate/e3abc781238cd0a3d16ffb3751d0fb77.png)
显示:

删除
drop关键字
删除:

显示:

三、表的操作——增删查改
1.创建表
用 () 括住,结束末尾使用 ; 一行写完用 , 先定义名称再定义类型
mysql> create table student(
-> id int ,
-> name varchar(20),
-> chinese int,
-> math int,
-> english int,
-> computer int);
);
2.增 insert
- 一行
一次增加一行数据
mysql> insert into student(id,name,chinese,math,english,computer)values
-> (1,'小红',78,65,88,96);
- 多行
一次增加多行数据
mysql> insert into student(id,name,chinese,math,english,computer)values
-> (2,'小明',95,88,76,68),
-> (3,'小张',75,68,55,80),
-> (4,'小林',85,68,77,96);

3.查 select
1.通配符
select * from student;
显示所有表
![[外链图片转存失败(img-ebRz96iv-1569143802319)(en-resource://database/1037:1)]](https://i-blog.csdnimg.cn/blog_migrate/94069bd005608fc74a340de85f265e75.png)
2.确定列
确定选择出的列
select sn,name,accout from student;

别名
修改某一列数据并对表头重新命名
mysql> select id,name,chinese+5 newChinese from student;

去重
去掉选中某列数据中重复的数据
mysql> select distinct math from student;

3.排序
对某一列数据进行排序,其中asc表示升序,desc表示降序
select * from student order by chinese asc; 升序
select * from student order by chinese desc; 降序

4.条件查找 where
- 查找> <
mysql> select * from student where chinese>80;

- 查找某一列中数据在某一区间内
使用between and 关键字
mysql> select * from student where english between 70 and 80;

- 查找指定两列
使用in关键字
mysql> select * from student where id in(2,4);

- 模糊查找
使用like关键字以及%通配符
mysql> select * from student where name like '%红';
mysql> select * from student where name like '小%';

- 多条件查找
where 条件一 and (条件2 or 条件三)
where 条件一 and (条件2 and 条件三)
mysql> select * from student where chinese > 80 and computer > 90;

4.修改 set
- 单个修改
一次修改一个值.
mysql> update student set chinese=80 where id=1;


- 多个修改
一次修改多个数值
mysql> update student set math=77,computer=89 where name like '%红';

5. 删除 delete
删除某一行数据
mysql> delete from student where id=4;

本文详细介绍SQL数据类型,包括数值、字符串、日期等,并讲解数据库库和表的基本操作,如创建、查询、修改、删除,以及如何使用条件、排序、去重等功能进行数据管理。
1672

被折叠的 条评论
为什么被折叠?



