前言
记录时间:2023.3.28
已坚持学习第30天
java从入门到精通
学习java时间历程记录打卡
早上7:00到 12:00
下午2:00到 5:00
JavaWeb-MySQL数据库总结
完成代码练习
1.数据库表创建
-- 查询所有数据库
show databases ;
-- 创建数据库
create database db02;
-- DDL : 表结构
-- 创建: 基本语法
create table tb_user(
id int comment 'ID, 唯一标识',
username varchar(20) comment '用户名',
name varchar(10) comment '姓名',
age int comment '年龄',
gender char(1) comment '性别'
) comment '用户表';
-- 创建: 基本语法 (约束)
create table tb_user(
id int primary key auto_increment comment 'ID, 唯一标识',
username varchar(20) not null unique comment '用户名',
name varchar(10) not null comment '姓名',
age int comment '年龄',
gender char(1) default '男' comment '性别'
) comment '用户表';
-- 图形化界面创建表 tb_emp
create table tb_emp(
id int primary key auto_increment comment '主键ID',
username varchar(20) not null comment '用户名',
password varchar(32) default '123456' null comment '密码',
name varchar(10) not null comment '姓名',
gender tinyint unsigned not null comment '性别, 1 男, 2 女',
image varchar(300) null comment '图像url',
job tinyint unsigned null comment '职位, 1 班主任 , 2 讲师 , 3 学工主管, 4 教研主管',
entrydate date null comment '入职日期',
create_time datetime not null comment '创建时间',
update_time datetime not null comment '修改时间',
constraint tb_emp_username_uindex unique (username)
) comment '员工表';
-- DDL: 查看表结构
-- 查看: 当前数据库下的表
show tables;
-- 查看: 查看指定表结构
desc tb_emp;
-- 查看: 数据库的建表语句
show create table tb_emp;
-- DDL: 修改表结构
-- 修改: 为表 tb_emp 添加字段 qq varchar(11)
alter table tb_emp add qq varchar(11) comment 'QQ';
-- 修改: 修改 tb_emp 字段类型 qq varchar(13)
alter table tb_emp modify qq_num varchar(13) comment 'QQ';
-- 修改: 修改 tb_emp 字段名 qq 为 qq_num varchar(13)
alter table tb_emp change qq_num qq_num varchar(13) comment 'QQ';
-- 修改: 删除 tb_emp 的 qq_num 字段
alter table tb_emp drop column qq_num;
-- 修改: 将tb_emp 表名修改为 emp
rename table tb_emp to emp;
-- DDL: 删除表结构
-- 删除: 删除 tb_emp 表
drop table if exists tb_emp;
-- DML : 数据操作语言
-- DML : 插入数据 - insert
-- 1. 为 tb_emp 表的 username, name, gender 字段插入值
insert into tb_emp(username,name,gender,create_time,update_time) values ('wuji','张无忌',1,now(),now());
-- 2. 为 tb_emp 表的 所有字段插入值
insert into tb_emp(id, username, password, name, gender, image, job, entrydate, create_time, update_time)
values (null,'zhiruo','123','周芷若',2,'1.jpg',1,'2010-01-01',now(),now());
insert into tb_emp values (null,'zhiruo2','123','周芷若',2,'1.jpg',1,'2010-01-01',now(),now());
-- 3. 批量为 为 tb_emp 表的 username , name , gender 字段插入数据
insert into tb_emp(username,name,gender,create_time,update_time) values
('weifuwang','韦一笑',1,now(),now()),('xieshiwang','谢逊',1,now(),now());
-- DML : 更新数据 - update
-- 1. 将 tb_emp 表的ID为1员工 姓名name字段更新为 '张三'
update tb_emp set name = '张三' , update_time = now() where id = 1;
-- 2. 将 tb_emp 表的所有员工的入职日期更新为 '2010-01-01'
update tb_emp set entrydate = '2010-01-01', update_time = now();
-- DML : 删除数据 - delete
-- 1. 删除 tb_emp 表中 ID为1的员工
delete from tb_emp where id = 1;
-- 2. 删除 tb_emp 表中的所有员工
delete from tb_emp;
2.表结构
4.表-数值类型
5.表-字符串类型
6.表-日期时间类型
视频总结
1. MySQL-课程介绍
https://www.bilibili.com/video/BV1m84y1w7Tb/?p=80
2. MySQL-概述-安装配置
https://www.bilibili.com/video/BV1m84y1w7Tb/?p=81
3. MySQL-概述-数据模型&SQL简介
https://www.bilibili.com/video/BV1m84y1w7Tb/?p=82
4. MySQL-DDL-数据库操作
https://www.bilibili.com/video/BV1m84y1w7Tb/?p=83
5. MySQL-DDL-图形化工具
https://www.bilibili.com/video/BV1m84y1w7Tb/?p=84
6. MySQL-DDL-表结构操作-创建
https://www.bilibili.com/video/BV1m84y1w7Tb/?p=85
7. MySQL-DDL-表结构操作-数据类型
https://www.bilibili.com/video/BV1m84y1w7Tb/?p=86
8. MySQL-DDL-表结构操作-创建-案例
https://www.bilibili.com/video/BV1m84y1w7Tb/?p=87
9. MySQL-DDL-表结构操作-查询&修改&删除
https://www.bilibili.com/video/BV1m84y1w7Tb/?p=88
10. MySQL-DML-添加数据insert
https://www.bilibili.com/video/BV1m84y1w7Tb/?p=89
11. MySQL-DML-修改数据update
https://www.bilibili.com/video/BV1m84y1w7Tb/?p=90
12. MySQL-DML-删除数据delete
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容