数据库名称可以为【schooldb】,字符集【utf8】,排序规则【utf8_general_ci】
建表语句
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '编号',
`createDate` datetime DEFAULT NULL,
`userName` varchar(20) DEFAULT NULL,
`pwd` varchar(36) DEFAULT NULL,
`phone` varchar(11) DEFAULT NULL,
`age` tinyint(3) DEFAULT NULL,
`sex` char(2) DEFAULT NULL,
`introduce` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
插入语句
insert into student values
(0,'2024-02-25 10:00:00','伯','123','18912345678',16,'女','hhh');
insert into student values
(0,'2024-02-25 10:00:00','仲','123','18912345678',18,'男','hhh');
insert into student values
(0,'2024-02-25 10:00:00','叔','123','18912345678',15,'男','hhh');
insert into student values
(0,'2024-02-25 10:00:00','季','123','18912345678',17,'女','hhh');
insert into student values
(0,'2024-02-25 10:00:00','伯子','123','18912345678',21,'男','hhh');
insert into student values
(0,'2024-02-25 10:00:00','仲子','123','18912345678',15,'女','hhh');
insert into student values
(0,'2024-02-25 10:00:00','季子','123','18912345678',19,'男','hhh');
查询语句
#like的使用语法,where后先写查询列再写like,最后写匹配字符串
SELECT * FROM student where userName like '%子';
SELECT * FROM student where pwd like '1%';
SELECT * FROM student where introduce like '%d%';
# 模糊查询基本上所有后台管理系统都会有此功能
select * from student where pwd is not null;
#范围查询 bewteen and 是包含==的,既可以查询数值范围,也可以查询时间范围,用途广泛。
select * from student where age between 15 and 20;
select * from student where createDate between '2024-02-21 00:00:00'and '2024-02-25 00:00:00';
# in关键字的使用 不建议使用这个关键字,因为它不一定走索引,在百万表的数据中会很卡
select * from student where userName in ('伯','仲','季子');