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=13 DEFAULT CHARSET=utf8;
2、插入数据——DML语句
INSERT INTO student VALUES(0,'2022-3-5 10:10:10','葫芦爷爷','123456','12345678948',69,'男','大爷就是大爷');
INSERT INTO student VALUES(0,'2022-3-5 10:10:10','葫芦1','123456','12345678948',2,'男','大娃力大无穷');
INSERT INTO student VALUES(0,'2022-3-5 10:10:10','葫芦2','123456','12345678948',2,'男','二娃千里眼');
INSERT INTO student VALUES(0,'2022-3-5 10:10:10','葫芦3','123456','12345678948',2,'男','三娃铜墙铁壁');
INSERT INTO student VALUES(0,'2022-3-5 10:10:10','葫芦4','123456','12345678948',2,'男','四娃会水');
INSERT INTO student VALUES(0,'2022-3-5 10:10:10','葫芦5','123456','12345678948',2,'男','五娃会火');
INSERT INTO student(userName,age,intrduce) VALUES('战神',255,'中国动漫');
3、基础查询语句——DQL
# 1、基础查询
select * from student;
# 2、分列匿名以及筛选数据查询
select userName as '姓名',age 年龄,sex '性别',introduce '简介'
from student
where pwd is not null;
# 3、去重查询
select distinct sex '性别类型' from student;
# 4、排序查询
select userName as '姓名',age 年龄,sex '性别',introduce '简介' from student ORDER BY age desc;
# 5、分页查询·limit这是个重载函数,
# 1个参数的limit用法是显示多少条信息
select * from student LIMIT 2;
# 2个参数,参数1:从第N条开始查询,N的起始坐标为0条。参数2:查询条数
select * from student limit 4,2;