MySQL创建数据库需要自行创建
数据库名称可以为【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','15612345678',16,'女','逍遥哥哥,你终于找到我了。')
INSERT into student values (0,'2024-02-25 10:00:00','王语嫣','123','15612345678',17,'女','慕容复,我跟你不共戴天。')
INSERT into student values (0,'2024-02-25 10:00:00','龙姑娘','123','15612345678',22,'女','我想过过过过过过的生活。')
INSERT into student values (0,'2024-02-25 10:00:00','杨过','123','15612345678',18,'男','一遇杨过误终身。')
INSERT into student values (0,'2024-02-25 10:00:00','杨逍','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 10:10:10 ' and '2024-02-25 10:10:10 ';、
#in关键字的使用,不建议使用这个关键字,因为它不一定走索引,在百万表的数据中会很卡。
SELECT * FROM `student`where userName in('赵灵儿','杨过','龙姑娘')
标签:10,00,like,DEFAULT,between,student,MySQL,NULL,where
From: https://blog.csdn.net/Xinghaoyang666/article/details/137116218