数据库名称可以是【school】,字符集【utf8】,顺序规则【utf8_general_ci】。
1、创建数据表——DDL语句
CREATE TABLE `student` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '学号',
`createDate` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
`userName` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '姓名',
`pwd` varchar(36) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '密码',
`phone` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '手机号',
`age` tinyint(3) NULL DEFAULT NULL COMMENT '年龄',
`sex` char(2) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '性别',
`introduce` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '简介',
PRIMARY KEY (`id`) USING BTREE
2、插入数据——DML语句
insert into student values(0,'2022-02-02 10:10:00','慢羊羊村长','123321','19965423256',60,'男','羊村的村长,孤寡老人');
insert into student values(0,'2022-02-02 10:10:00','喜羊羊','123321','19965423256',12,'男','羊村智慧担当,所有羊都喜欢和他玩');
insert into student values(0,'2022-02-02 10:10:00','美羊羊','123321','19965423456',9,'女','漂亮的一只小羊');
insert into student values(0,'2022-02-02 10:10:00','沸羊羊','123321','19965426556',12,'男','长得有点黑,舔狗');
insert into student values(0,'2022-02-02 10:10:00','暖洋洋','123321','19965423256',11,'女','知心小姐姐');
insert into student values(0,'2022-02-02 10:10:00','懒洋洋','123321','19965423256',9,'女','非常可爱,喜欢吃喝睡');
insert into student values(0,'2022-02-02 10:10:00','小灰灰','123321','19965423256',9,'男','灰太狼的儿子');
SELECT * FROM student;
3、基础语句——DQL
select userName as '用户名',age 年龄,sex '性 别',introduce '简介'
from student where pwd is not null;
# 去重查询dis tin ct
select distinct sex '性别类型' from student;
# 排序order by
select * from student order by userName desc;
# 分页查询 -limit·是一个重载的函数,当只有1个参数的时候代表显示行数
# 两个参数limit分页:参数1、从N行开始查询=(当前页-1)*每页条数
select * from student limit 6,3;