MySQL创建数据库需要自行创建,
1、学生表DDL
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '学号',
`createDate` datetime DEFAULT NULL COMMENT '开始日期',
`userName` varchar(20) DEFAULT NULL COMMENT '用户名',
`pwd` varchar(36) DEFAULT NULL COMMENT '密码',
`phone` varchar(11) DEFAULT NULL COMMENT '电话',
`age` tinyint(3) DEFAULT NULL COMMENT '年龄',
`sex` char(2) DEFAULT NULL COMMENT '性别',
`introduce` varchar(255) DEFAULT NULL COMMENT '介绍',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
2、插入学生信息DMl
select * from student;
insert into student values(0,'2024-02-25 10:00:00','赵灵儿','123',
'12345678901',16,'女','逍遥哥哥,你终于找到我了。');
insert into student values(0,'2024-02-25 10:00:00','龙姑娘','124',
'12345678902',16,'女','我想过过过儿过过的日子');
insert into student values(0,'2024-02-25 10:00:00','王语嫣','125',
'12345678903',16,'女','慕容复,我和你不共戴天');
insert into student values(0,'2024-02-25 10:00:00','杨瀚森','126',
'12345678904',19,'男','来自邯郸广平的天才少年');
insert into student values(0,'2024-02-25 10:00:00','贾斯汀','127',
'12345678905',19,'男','来自衡水饶阳的电竞天才少年');
insert into student values(0,'2024-02-25 10:00:00','王哲林','128',
'12345678906',19,'男','来自邯郸魏县的台球天才少年');
insert into student values(0,'2024-02-25 10:00:00','李 宁','129',
'12345678907',19,'男','来自沧州黄骅的篮球天才少年');
实际效果:
3、基础查询测试DQL
#基础查询
select * from student;
#筛选列(匿名)与筛选数据行
select userName as 姓名,age'年龄',sex '性别',introduce'简介'
from student
where pwd is not null;
#分页 limit·有两个重载函数常用
#1、一个参数为显示条数
#2、一个参数为从那条开始查询(下标从0开始计算),零——参数为显示条数
select * from student limit 3,2;# 从4(0-3)开始查询2条。
# 排序,order by根据数据值类型进行排序会比较准确。
select * from student order by age desc limit 3;
# 去重语句distinct
select distinct sex '性别类型' from student;
只看不赞 发量减半!
标签:COMMENT,25,00,DEFAULT,DDL,student,SQL,DQL,NULL From: https://blog.csdn.net/2301_80888325/article/details/137008963