1. 为什么要使用数据库
    解决数据持久化问题
    高效的管理数据(增删改查)
  2. 数据库的分类:
    关系型数据库

    • 理论基础:关系代数
    • 具体表象:二维表
      行:记录
      列:字段
    • 编程语言:SQL(结构化查询语言)
      DDL - 数据定义语言 —> create / drop / alter
      DML - 数据操作语言 —> insert / delete / update
      DQL - 数据查询语言 —> select
      DCL - 数据控制语言 —> grant / revoke
    非关系型数据库(NoSQL / NewSQL)

    • MongoDB —> 文档数据库
    • Redis —> KV数据库
  3. 相关术语
    DB - database
    DBA - database administrator
    DBMS - database management system
    DBS - database system
  4. 使用MySQL

    查看所有数据库:show databases;

    切换数据库:use school;

    查看数据库下所有的表:show tables;

    查看所有的字符集(编码):show charset;

    查看所有的校对(排序)规则:show collation;

    查看所有的引擎:show engines;

    创建/删除数据库:
    create schema school default charset utf8mb4;
    create database school default charset utf8mb4 collate utf8mb4_bin;
    create database school default character set utf8mb4;
    drop database if exists school;

    创建/删除/修改二维表:

      create table tb_student (列名 数据类型 约束条件);drop table tb_student;alter table tb_student add column ...;alter table tb_student drop column ...;alter table tb_student modify column ...;alter table tb_student change column ...;alter table tb_student add constraint ...;alter table tb_student drop constraint ...;
    
    - 主键(primary key):能够唯一确定一条记录的字段。
    - 外键(foreign key):外来的主键(其他表的主键)。
    

    ~ 插入/删除/更新数据:

      insert into tb_student (...) values (...);insert into tb_student (...) values (...), (...), (...);
    
    delete from tb_student where stu_id=...;
    delete from tb_student where stu_id in (...);update tb_student set ..., ... where stu_id=...;
    
  5. MySQL的数据类型 —> ? data types;

    整数:

    • int / integer —> -2^31 ~ 2^31 - 1

      • int unsigned —> 0 ~ 2^32 - 1
      • bigint —> -2^63 ~ 2^63 - 1
      • bigint unsigned —> 0 ~ 2^64 - 1
      • smallint —> -32768 ~ 32767
      • smallint unsigned —> 0 ~ 65535
      • tinyint —> -128 ~ 127
      • tinyint unsigned —> 0 ~ 255

    小数:
    - float / double
    - decimal —> decimal(10,2)

    字符串:

    • char(N) / varchar(N)
    • longtext —> longblob(二进制大对象)—> 4G —> 放资源路径(URL)

    时间日期:

    • date / time / datetime(6)

      • timestamp —> 1970-1-1 00:00:00

创建学院表 学生表 教师表 课程表 选课记录表

-- 如果存在名为school的数据库就删除它
drop database if exists `school`;-- 创建名为school的数据库并设置默认的字符集和排序方式
create database `school` default character set utf8mb4;-- 切换到school数据库上下文环境
use `school`;-- 创建学院表
create table `tb_college`
(
`col_id` int unsigned auto_increment comment '编号',
`col_name` varchar(50) not null comment '名称',
`col_intro` varchar(5000) default '' comment '介绍',
primary key (`col_id`)
) engine=innodb comment '学院表';-- 创建学生表
create table `tb_student`
(
`stu_id` int unsigned not null comment '学号',
`stu_name` varchar(20) not null comment '姓名',
`stu_sex` boolean default 1 comment '性别',
`stu_birth` date not null comment '出生日期',
`stu_addr` varchar(255) default '' comment '籍贯',
`col_id` int unsigned not null comment '所属学院',
primary key (`stu_id`),
foreign key (`col_id`) references `tb_college` (`col_id`)
) engine=innodb comment '学生表';-- 创建教师表
create table `tb_teacher`
(
`tea_id` int unsigned not null comment '工号',
`tea_name` varchar(20) not null comment '姓名',
`tea_title` varchar(10) default '助教' comment '职称',
`col_id` int unsigned not null comment '所属学院',
primary key (`tea_id`),
foreign key (`col_id`) references `tb_college` (`col_id`)
) engine=innodb comment '老师表';-- 创建课程表
create table `tb_course`
(
`cou_id` int unsigned not null comment '编号',
`cou_name` varchar(50) not null comment '名称',
`cou_credit` int not null comment '学分',
`tea_id` int unsigned not null comment '授课老师',
primary key (`cou_id`),
foreign key (`tea_id`) references `tb_teacher` (`tea_id`)
) engine=innodb comment '课程表';-- 创建选课记录表
create table `tb_record`
(
`rec_id` bigint unsigned auto_increment comment '选课记录号',
`sid` int unsigned not null comment '学号',
`cid` int unsigned not null comment '课程编号',
`sel_date` date not null comment '选课日期',
`score` decimal(4,1) comment '考试成绩',
primary key (`rec_id`),
foreign key (`sid`) references `tb_student` (`stu_id`),
foreign key (`cid`) references `tb_course` (`cou_id`),
unique (`sid`, `cid`)
) engine=innodb comment '选课记录表';

建表数据

use school;-- 插入学院数据
insert into `tb_college` (`col_name`, `col_intro`)
values ('计算机学院', '计算机学院1958年设立计算机专业,1981年建立计算机科学系,1998年设立计算机学院,2005年5月,为了进一步整合教学和科研资源,学校决定,计算机学院和软件学院行政班子合并统一运作、实行教学和学生管理独立运行的模式。 学院下设三个系:计算机科学与技术系、物联网工程系、计算金融系;两个研究所:图象图形研究所、网络空间安全研究院(2015年成立);三个教学实验中心:计算机基础教学实验中心、IBM技术中心和计算机专业实验中心。'),('外国语学院', '外国语学院设有7个教学单位,6个文理兼收的本科专业;拥有1个一级学科博士授予点,3个二级学科博士授予点,5个一级学科硕士学位授权点,5个二级学科硕士学位授权点,5个硕士专业授权领域,同时还有2个硕士专业学位(MTI)专业;有教职员工210余人,其中教授、副教授80余人,教师中获得中国国内外名校博士学位和正在职攻读博士学位的教师比例占专任教师的60%以上。'),('经济管理学院', '经济学院前身是创办于1905年的经济科;已故经济学家彭迪先、张与九、蒋学模、胡寄窗、陶大镛、胡代光,以及当代学者刘诗白等曾先后在此任教或学习。');-- 插入学生数据
insert into `tb_student` (`stu_id`, `stu_name`, `stu_sex`, `stu_birth`, `stu_addr`, `col_id`)
values(1001, '杨过', 1, '1990-3-4', '湖南长沙', 1),(1002, '任我行', 1, '1992-2-2', '湖南长沙', 1),(1033, '王语嫣', 0, '1989-12-3', '四川成都', 1),(1572, '岳不群', 1, '1993-7-19', '陕西咸阳', 1),(1378, '纪嫣然', 0, '1995-8-12', '四川绵阳', 1),(1954, '林平之', 1, '1994-9-20', '福建莆田', 1),(2035, '东方不败', 1, '1988-6-30', null, 2),(3011, '林震南', 1, '1985-12-12', '福建莆田', 3),(3755, '项少龙', 1, '1993-1-25', null, 3),(3923, '杨不悔', 0, '1985-4-17', '四川成都', 3);-- 插入老师数据
insert into `tb_teacher` (`tea_id`, `tea_name`, `tea_title`, `col_id`)
values (1122, '张三丰', '教授', 1),(1133, '宋远桥', '副教授', 1),(1144, '杨逍', '副教授', 1),(2255, '范遥', '副教授', 2),(3366, '韦一笑', default, 3);-- 插入课程数据
insert into `tb_course` (`cou_id`, `cou_name`, `cou_credit`, `tea_id`)
values (1111, 'Python程序设计', 3, 1122),(2222, 'Web前端开发', 2, 1122),(3333, '操作系统', 4, 1122),(4444, '计算机网络', 2, 1133),(5555, '编译原理', 4, 1144),(6666, '算法和数据结构', 3, 1144),(7777, '经贸法语', 3, 2255),(8888, '成本会计', 2, 3366),(9999, '审计学', 3, 3366);-- 插入选课数据
insert into `tb_record` (`sid`, `cid`, `sel_date`, `score`)
values (1001, 1111, '2017-09-01', 95),(1001, 2222, '2017-09-01', 87.5),(1001, 3333, '2017-09-01', 100),(1001, 4444, '2018-09-03', null),(1001, 6666, '2017-09-02', 100),(1002, 1111, '2017-09-03', 65),(1002, 5555, '2017-09-01', 42),(1033, 1111, '2017-09-03', 92.5),(1033, 4444, '2017-09-01', 78),(1033, 5555, '2017-09-01', 82.5),(1572, 1111, '2017-09-02', 78),(1378, 1111, '2017-09-05', 82),(1378, 7777, '2017-09-02', 65.5),(2035, 7777, '2018-09-03', 88),(2035, 9999, '2019-09-02', null),(3755, 1111, '2019-09-02', null),(3755, 8888, '2019-09-02', null),(3755, 9999, '2017-09-01', 92);

, 82),
(1378, 7777, ‘2017-09-02’, 65.5),
(2035, 7777, ‘2018-09-03’, 88),
(2035, 9999, ‘2019-09-02’, null),
(3755, 1111, ‘2019-09-02’, null),
(3755, 8888, ‘2019-09-02’, null),
(3755, 9999, ‘2017-09-01’, 92);
``
EER图是一种物理模型,与落地的数据库(Mysql)相关,长这样的
ER图是逻辑模型,也叫实体属性图

创建学院表 学生表 教师表 课程表 选课记录表相关推荐

  1. JavaWeb第九次:程序设计题:在MySQL,创建一个学生信息数据库Student,创建一张学生注册信息表message,包含name (姓名)、age (年龄)、sex (性别)、educ

    程序设计题: 在MySQL,创建一个学生信息数据库Student,创建一张学生注册信息表message,包含name (姓名).age (年龄).sex (性别).education(学历).phon ...

  2. MySQL全方位练习(学生表 教师表 课程表 分数表)

    一.创建表并初始化数据 1.表说明 student(学生表).teacher(教师表).course(课程表).sc(分数表) 2.创建表 [sql]  view plain copy create  ...

  3. MySQL8.0 小白入门 46条sql语句练习(学生表 教师表 课程表 分数表)

    4 Tab for MySQL8.0 1.表说明 2.创建表 3.插入数据 4.查询语句(46条) 1.表说明 – 数据库版本:mysql8 – 数据表说明:student(学生表).teacher( ...

  4. 创建一个数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)

    创建一个数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2的 ...

  5. mysql创建教师表_day34 mysql 认识数据库,创建学生,教师,学院表

    数据库 - 数据的仓库(集散地) - database - 实现数据持久化和数据管理 持久化 - 将数据从内存转移到能够长久保存数据的存储介质的过程 数据库的分类:关系型数据库(SQL)和非关系型数据 ...

  6. 设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。...

    一.            设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表( ...

  7. mysql经典四表查询_mysql经典问题四表查询(教师,学生,成绩,课程表)

    创建数据库 1.创建一个数据库 create database work;web 2.进入数据库work use work;数据库 3.数据库默认编码可能不支持中文,能够在这里设置下 set name ...

  8. mysql:设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)。四个表的结构分别如表1-1的表(一)表(四)所示

    设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)表(四)所示,数据如表1-2的表( ...

  9. 设有一数据库,包括四个表:学生表(Student)、课程表(Course)、成绩表(Score)以及教师信息表(Teacher)

    设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2的表 ...

最新文章

  1. Android:你好,androidX!再见,android.support
  2. 创业互联网公司如何搭建自己的技术架构
  3. 前端学习(3120):react-hello-react的setstate的使用
  4. linux —— shell 编程(文本处理)
  5. 深度学习《patchGAN》
  6. oracle索引未使用,oracle - 未使用主键索引 - SO中文参考 - www.soinside.com
  7. POI中设置Excel单元格格式
  8. nodejs图片读取
  9. Golang defer 快速上手
  10. python mro文件_python MRO问题
  11. 浅谈OLAP系统核心技术点
  12. Java开发面试必问项。标识符、字面值、变量、数据类型,该学了
  13. 2022第九届生物发酵展(济南)3月召开,拓展生物发酵行业新机遇
  14. 电话程控交换机 配置
  15. 计算机二级考试公网入口和教育网入口,考试入口
  16. Unity教程 | 手把手教你拼一个3D“魔方”
  17. 1秒50万字!js实现关键词匹配
  18. 【元器件】电容选型指南
  19. Python 语言中的骚操作
  20. 课后作业——Day6

热门文章

  1. python的def语句例题_下列 Python语句的输出结果是?
  2. Windows 应急响应篇(保姆级检查流程)
  3. springsecurity oauth2.0 集成sso单点登录
  4. OpenLayers学习笔记高级篇(一、openlayers画点线面)
  5. Excell表格的技巧
  6. Android-基站信息-信号路测-SignalSiteMap-帮您找到附近的基站
  7. Matlab编程算法中S函数的使用方法
  8. 数学建模的理论及案例
  9. 前端小白的html+css入门笔记
  10. JS中数值类型的本质