MySQL日常语句练习——单表DDL_DML_DQL语句练习

数据库名称可以为【schoolDB】,字符集【utf8】,排序规则【utf8_general_ci】

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=26 DEFAULT CHARSET=utf8;

2、插入数据——DML语句

INSERT INTO student VALUES(0,'2024-02-25 20:03:00', '宋江','123466','15963247887',50,'男','000');
INSERT INTO student VALUES(0,'2024-02-25 20:03:00', '林冲','123466','15963247887',44,'男','000');
INSERT INTO student VALUES(0,'2024-02-25 20:03:00', '鲁智深','123466','15963247887',32,'男','000');
INSERT INTO student VALUES(0,'2024-02-25 20:03:00', '武松','123466','15963247887',40,'男','000');
INSERT INTO student VALUES(0,'2024-02-25 20:03:00', '诸葛亮','123466','15963247887',30,'男','000');
INSERT INTO student VALUES(0,'2024-02-25 20:03:00', '刘备','123466','15963247887',19,'男','000');
INSERT INTO student VALUES(0,'2024-02-25 20:03:00', '曹操','123466','15963247887',36,'男','000');
INSERT INTO student VALUES(0,'2024-02-25 20:03:00', '关羽','123466','15963247887',56,'男','000');
INSERT INTO student VALUES(0,'2024-02-25 20:03:00', '张飞','123466','15963247887',25,'男','000');
INSERT INTO student VALUES(0,'2024-02-25 20:03:00', '曹丕','123466','15963247887',23,'男','000');
INSERT INTO student VALUES(0,'2024-02-25 20:03:00', '周瑜','123466','15963247887',28,'男','000');
INSERT INTO student VALUES(0,'2024-02-25 20:03:00', '大乔','123466','15963247887',20,'女','000');
INSERT INTO student (userName,age,introduce) VALUES('小乔',30,'555');
select * from student;

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)*显示页数
select *from student limit 7,4;
#排序
select *from student order by age asc;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值