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) unsigned DEFAULT NULL COMMENT '年龄',
`sex` char(2) DEFAULT NULL COMMENT '性别',
`introduce` varchar(255) DEFAULT NULL COMMENT '简介',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;
2、插入数据——DML语句
insert into student values(0,'2024-02-20 10:00:00','盘古','123456','13654217854',255,'神','开天辟地');
insert into student values(0,'2024-02-20 10:00:00','女娲','123456','13654217854',200,'神','造人补天');
insert into student values(0,'2024-02-20 10:00:00','伏羲','123456','13654217854',215,'神','先天八卦');
insert into student values(0,'2024-02-20 10:00:00','神农','123456','13654217854',155,'神','尝百草');
insert into student values(0,'2024-02-20 10:00:00','嫘祖','123456','13654217854',115,'神','养蚕织布');
insert into student values(0,'2024-02-20 10:00:00','蚩尤','123456','13654217854',155,'神','锻造大神,坐下食铁巨兽');
insert into student (userName,age,introduce) values('仓颉',125,'造字');
3、基础查询——DQL语句
# 基础查询
select * from student;
# 非空查询
select userName as '姓名',age 年龄,sex '性 别',introduce '介 绍'from student where pwd is not null;
# 去重查询
select distinct sex '性别' from student;
# 分页查询关键字limit有两个参数,只写1个代表查询条数。
# 第一个参数代表起始查询位置,第二个参数代表查询行数。
# 计算初始分页条数=(当前页-1)*显示条数
select * from student limit 6,3;
# 排序
select * from student order by age asc;