前言
数据库名称可以为【schoolDB】,字符集【utf8】,排序规则【utf8-general-ci】。
1·建表语句——DDL
CREATE TABLE `biao` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '学号',
`creatdate` 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=2 DEFAULT CHARSET=utf8;
2·插入语句——DML
insert into student values(0,'2024-02-25 10:10:10','赵灵儿','123',
'15612345678',16,'女','逍遥哥哥,你终于找到我了。');
insert into student values(0,'2024-02-25 10:10:10','王语嫣','123',
'15612345678',17,'女','慕容复,我和你不共戴天。');
insert into student values(0,'2024-02-25 10:10:10','龙姑娘','123',
'15612345678',22,'女','我想过过过儿过过的日子。');
insert into student values(0,'2024-02-25 10:10:10','杨过','123',
'15612345678',18,'男','一遇杨过误终身。');
insert into student values(0,'2024-02-25 10:10:10','杨逍','123',
'15612345678',27,'男','杨过跟程英的大儿子。');
insert into student (userName,age,introduce)values('黄衣女子',26,'杨过与龙姑娘的大女儿。');
3基础查询测试DQL
#1,基础查询
SELECT * FROM study;
#2,分列匿名以及筛选数据查询
SELECT username AS '姓名',age '年龄',sex '性别',introduce'简介'
FROM study
WHERE pwd IS NOT NULL;
#3,去重查询
SELECT DISTINCT sex '性别类型'FROM study;
#4,排序查询
select username as '姓名',age '年龄',sex'性别',introduce'简介'FROM study ORDER BY age desc;
#5,分页查询·limit用法是显示多少条信息
SELECT * FROM study LIMIT 2;
#2个参数,参数1:从第n条开始查询,n的起始坐标为0条。参数2:查询条数
SELECT * FROM study LIMIT 4,2;