diff --git "a/49 \346\235\216\350\210\222\346\261\266/9.7\346\225\260\346\215\256\345\272\223\351\253\230\347\272\247.md" "b/49 \346\235\216\350\210\222\346\261\266/9.7\346\225\260\346\215\256\345\272\223\351\253\230\347\272\247.md" new file mode 100644 index 0000000000000000000000000000000000000000..fc10d4d96b100e6c1868615b5ba746a93e7b660f --- /dev/null +++ "b/49 \346\235\216\350\210\222\346\261\266/9.7\346\225\260\346\215\256\345\272\223\351\253\230\347\272\247.md" @@ -0,0 +1,97 @@ +- ## 数据库高级 +1. 什么是ER图? + 1.实体关系图。 + 2.三要素:实体,属性,关系。 + +## 数据库的范式 + +1.第一范式:要求字段的内容,不可再分割,为的是保证数据的原性。 + +例:姓名;省份,城市,区,县,街道 + +2.第二范式:要求在满足第一范式胡基础上,要求非主键字段要完全依赖主键(非主键,要依赖整个联合主键),而不能只依赖部分 + +3.第三范式:满足第二范式的前提上,要求非主键属性要直接依赖于主键 + +```java +-- 创建数据库 +create database school2 charset utf8; + +-- 使用数据库 +use school2; + +-- 院系表 +CREATE TABLE department( + de_id int PRIMARY key auto_increment, + de_name VARCHAR(20), + de_tel varchar(20) +); + + +-- 专业表 +create table major( + ma_id int primary key auto_increment, + ma_name varchar(10), + de_id int, + foreign key (de_id) references department(de_id) +); + + +-- 班级表 +create table class( + cl_id int primary key, + cl_name varchar(10), + m_id int, + foreign key (m_id) references major(m_id) +); + + +-- 学生表 +create table student( + stu_id int primary key, + stu_name varchar(5), + stu_gender varchar(1), + stu_age int, + cl_id int, + foreign key (cl_id) references class(cl_id) +); + +-- 课程信息表 +create table course( + cu_id int primary key, + cu_name varchar(6), + stu_id int, + foreign key (stu_id) references student(stu_id) +); + +-- 教师表 +create table teacher( + te_id int primary key, + te_name varchar(5), + cu_id int, + foreign key (cu_id) references course(cu_id) +); + +-- 教室表 +create table classroom( + cr_id int primary key, + cr_name varchar(6), + cr_address varchar(20), + cu_id int, + foreign key (cu_id) references course(cu_id) +); + +-- 课程表 +create table timetable( + ti_week varchar(3), + ti_time int, + cl_id int, # 班级编号 + foreign key (cl_id) references class(cl_id), + stu_id int, # 学生编号 + foreign key (stu_id) references student(stu_id), + cu_id int, # 课程编号 + foreign key (cu_id) references course(cu_id), + te_id int, # 教师编号 + foreign key (te_id) references teacher(te_id) +); +```