数据库名称可以为【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=7 DEFAULT CHARSET=utf8;
插入数据
insert into student values(0,'2024-02-21 10:10:10','赵灵儿','123',
'15612345678',16,'女','逍遥哥哥,你终于找到我了');
insert into student values(0,'2024-02-25 10:10:10','王语嫣','123',
'15612345678',17,'女','慕容复,我和你不共戴天。');
insert into student values(0,'2024-02-22 10:10:10','龙姑娘','123',
'15612345678',22,'女','我想过过过儿过过的日子。');
insert into student values(0,'2024-02-14 10:10:10','杨过','123',
'15612345678',18,'男','一遇杨过误终身。');
insert into student values(0,'2024-02-25 10:10:10','杨逍遥','123',
'15612345678',27,'男','杨过和程英的大儿子。');
insert into student(userName,age,introduce) values('黄衣女子',26,
'杨过与龙姑娘的大女儿。');
模糊查询语句
#like的使用语法,where后 先写查询列再写like,最后写匹配字符串
SELECT * FROM student where userName like '杨_';
SELECT * FROM student where userName like '杨%';
SELECT * FROM student where introduce like '%大%';
#模糊查询基本上所有后台管理系统都会有此功能
select * from student where pwd is not null;
#范围查询·between and是包含==的,既可以查询数值范围,也可以查询时间范围,用途广泛。
select * from student where age between 22 and 30;
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 ('赵灵儿','杨过','龙姑娘');
标签:02,10,DEFAULT,数据库,模糊,查询,student,NULL,where
From: https://blog.csdn.net/2302_81910251/article/details/137117514