首页 > 数据库 >MySQL日常练习——单表DDL DML DQL

MySQL日常练习——单表DDL DML DQL

时间:2024-03-25 15:02:51浏览次数:26  
标签:COMMENT 00 DEFAULT DML 单表 student DQL NULL select

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 '男' COMMENT '性别',
  `introduce` varchar(255) DEFAULT NULL COMMENT '简介',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

2.插入语句——DML

insert into student values(0,'2024-02-25 10:00:00','刘德华','123456','12345678901',62,'男','男神');
insert into student values(0,'2024-02-25 10:00:00','刘青云','123456','12345678901',65,'男','演员');
insert into student values(0,'2024-02-25 10:00:00','周星驰','123456','12345678901',61,'男','爱情');
insert into student values(0,'2024-02-25 10:00:00','张翰','123456','12345678901',32,'男','流星雨');
insert into student values(0,'2024-02-25 10:00:00','王祖贤','123456','12345678901',27,'女','女神');
insert into student  (userName,age,introduce)values('刘亦菲',37,'神仙姐姐');
select * from student;

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 年龄,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;

标签:COMMENT,00,DEFAULT,DML,单表,student,DQL,NULL,select
From: https://blog.csdn.net/2302_81782153/article/details/137013223

相关文章

  • MySQL日常语句练习——单表DDL_DML_DQL语句练习
    前言数据库名称可以为{schoolDB},字符集【utf8】,排列规则【utf8_general_ci】。1、建表语句——DDLCREATETABLE`student`(`id`int(11)NOTNULLAUTO_INCREMENTCOMMENT'学号',`createDate`datetimeDEFAULTNULLCOMMENT'创建时间',`userName`varchar(2......
  • MySQL日常语句练习——单表DDL_DML_DQL语句练习
    前言数据库名称可以为【schoolDB】、字符集【utf8】、排序规则【utf8_general_ci】。1、建表语句——DDLCREATETABLE`student`(`id`int(11)NOTNULLAUTO_INCREMENTCOMMENT'学号',`createDate`datetimeDEFAULTNULLCOMMENT'创建时间',`userName`varcha......
  • MySQL学习必备SQL_DDL_DQL
    1.学生表CREATETABLE`student`(`id`int(11)NOTNULLAUTO_INCREMENTCOMMENT'学号',`createDate`datetimeDEFAULTNULL,`userName`varchar(20)DEFAULTNULL,`pwd`varchar(36)DEFAULTNULL,`phone`varchar(11)DEFAULTNULL,`age`tinyin......
  • MySQL 学习必备SQL_DDL_DML_DQL
    mySQL创建数据库需要自行创建,数据库名称可以为【schoolDB】,字符集【utf8】,排列规则【utf8_general_ci】,21、学生表DDLCREATETABLE`student`(`id`int(11)NOTNULLAUTO_INCREMENTCOMMENT'学号',`creatDate`datetimeDEFAULTNULL,`userName`varchar(20)D......
  • MySQL学习必备SQL_DDL_DML_DQL
    MySQL创建数据库需要自行创建,数据库名称可以为【schoolDB】,字符集【utf-8】,排序规则【utf8_general_ci】。1、学习表DDLCREATETABLE`student`(`id`int(11)NOTNULLAUTO_INCREMENT,`createDate`datetimeDEFAULTNULL,`userName`varchar(20)DEFAULTNULL,......
  • MySQL学习必备SQL_DDL_DML_DQL
    MySQL创建数据库需要自行创建,数据库名称可以为【schoolDB】,字符集【utf8】,排序规则【utf8_general_ci】1、学生表DDLCREATETABLE`student`(`id`int(11)NOTNULLAUTO_INCREMENTCOMMENT'学号',`createDate`datetimeDEFAULTNULL,`userName`varchar(20)DEF......
  • MySQL学习必备SQL_DDL_DML+DQL
    MySQL创建数据库需要自行创建,数据库名称可以为【schoolDb】,字符集【utf8】,【utf8_general_ci】1.学生表CREATETABLE`student`(`id`int(11)NOTNULLAUTO_INCREMENTCOMMENT'学号',`createDate`datetimeDEFAULTNULL,`userName`varchar(20)DEFAULTNULL,......
  • MySQL学习必备SQL_DDL_DML_DQL
    mysql创建1、学生表CREATETABLE`student`(`id`int(11)NOTNULLAUTO_INCREMENTCOMMENT'学号',`createdate`datetimeDEFAULTNULL,`username`varchar(20)DEFAULTNULL,`pwd`varchar(36)DEFAULTNULL,`phone`varchar(11)DEFAULTNULL,`age......
  • MySQL学习必备SQL-DDL-DQL
    MySQL创建数据库需要自行创建,1、学生表DDLCREATETABLE`student`(`id`int(11)NOTNULLAUTO_INCREMENTCOMMENT'学号',`createDate`datetimeDEFAULTNULLCOMMENT'开始日期',`userName`varchar(20)DEFAULTNULLCOMMENT'用户名',`pwd`varcha......
  • MySQL学习必备SQL_DDL_DML_DQL
    1.MySQL数据库创建(学生表)CREATETABLE`student`(`id`int(11)NOTNULLAUTO_INCREMENT,`createdate`datetimeDEFAULTNULL,`username`varchar(255)CHARACTERSETutf8DEFAULTNULL,`pwd`varchar(255)CHARACTERSETutf8DEFAULTNULL,`phone`varcha......