diff --git "a/\351\231\210\346\231\272\345\256\217/20240904\347\254\224\350\256\260.md" "b/\351\231\210\346\231\272\345\256\217/20240904\347\254\224\350\256\260.md" index 288dbfe02a11477f303343e0b35588a9ff25854f..524b266162a453140557b34c545de1e83fb461f9 100644 --- "a/\351\231\210\346\231\272\345\256\217/20240904\347\254\224\350\256\260.md" +++ "b/\351\231\210\346\231\272\345\256\217/20240904\347\254\224\350\256\260.md" @@ -1,19 +1,177 @@ -# 数据库高级应用 - -## 1. 数据库设计基础 - 1. 表与表的关系 - 2. ER图 - 3. 数据库的三式范式 - 4. 设计数据库的软件 -## 2. 数据库设计基础进阶 - 1. RBAC与SKU -## 3. 数据库高阶语法 - 1. 自连接,左连接,右连接,外连接 - 2. 视图 - 3. 单行函数 - 4. 存储过程 - 5. 分支结构、循环结构 :if while for - 6. 窗口函数 - 7. 触发器 - 8. 索引 - 9. 事务 \ No newline at end of file +## 需求 + +### 表与表之间的关系 + +有三种分别是:一对一,一对多,多对一。 + +其中一对一:一个实体的每个实例只关联另一个实体的一个实例。 + +``` + 一对多:一个实体的每个实例可以关联另一个实体的多个实例 + + 多对多:两个实体的多个实例之间可以相互关联 +``` + +### 如何让两个表之间产生联系 + +一对一:任何一方的主键成为另一张表的外键 + +一对多:用一的主键成为多的外键 + +多对多:通过第三个表,使其转换为两个一对多 + +### 三大范式 + +首先什么是范式?答:是数据库实际表的一个原则 + +###### 第一范式:列不可再分 + +确保每一列原子性 + +###### 第二范式:属性完全依赖于主键 + +即每一行的数据只能与其中一列相关,即一行数据只做一件事。只要数据列中出现数据重复,就要把表拆分开来。如一个人同时订几个房间,就会出来一个订单号多条数据,这样子联系人都是重复的,就会造成数据冗余。我们应该把他拆开来 + +###### 第三范式:属性不依赖于其他非主属性,属性直接依赖于主键 + +即数据不能存在传递关系,即每个属性都跟主键有直接关系而不是间接关系如比如Student表(学号,姓名,年龄,性别,所在院校,院校地址,院校电话)这样一个表结构,就存在上述关系 + +## 建表 + +```sql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2024/9/4 20:42:42 */ +/*==============================================================*/ + +DROP DATABASE IF EXISTS glxt; +CREATE DATABASE glxt CHARACTER SET utf8; +use glxt; + +drop table if exists reponsible2; + +drop table if exists manager; + +drop table if exists porject; + +drop table if exists reponsible; + +drop table if exists section; + +drop table if exists staff; + + +/*==============================================================*/ +/* Table: reponsible2 */ +/*==============================================================*/ +create table reponsible2 +( + did int primary key auto_increment not null, + pid int not null, + sid int not null +); + +/*==============================================================*/ +/* Table: manager */ +/*==============================================================*/ +create table manager +( + id int primary key auto_increment not null, + bid int, + name varchar(5) +); + +/*==============================================================*/ +/* Table: porject */ +/*==============================================================*/ +create table porject +( + pid int primary key auto_increment not null, + pname varchar(255) +); + +/*==============================================================*/ +/* Table: reponsible */ +/*==============================================================*/ +create table reponsible +( + cid int primary key auto_increment not null, + pid int not null, + bid int not null +); + +/*==============================================================*/ +/* Table: section */ +/*==============================================================*/ +create table section +( + bid int primary key auto_increment not null, + bname varchar(255) +); + +/*==============================================================*/ +/* Table: staff */ +/*==============================================================*/ +create table staff +( + sid int primary key auto_increment not null, + bid int not null, + sname varchar(5), + sphone int +); + +alter table reponsible2 add constraint FK_f1 foreign key (pid) + references porject (pid) on delete restrict on update restrict; + +alter table reponsible2 add constraint FK_f2 foreign key (sid) + references staff (sid) on delete restrict on update restrict; + +alter table manager add constraint FK_gl foreign key (bid) + references section (bid) on delete restrict on update restrict; + +alter table reponsible add constraint FK_reponsible foreign key (pid) + references porject (pid) on delete restrict on update restrict; + +alter table reponsible add constraint FK_reponsible2 foreign key (bid) + references section (bid) on delete restrict on update restrict; + +alter table staff add constraint FK_life foreign key (bid) + references section (bid) on delete restrict on update restrict; +INSERT into section(bname)value +('前端'), +('后端'); +INSERT into manager(bid,name)VALUES(1,'李华'),(2,'肖康');INSERT into staff(bid,sname,sphone)VALUES +(1,'张三',10000), +(1,'李四',10086), +(2,'王五',10001) +; +INSERT into porject(pname)value +('微信小程序'), +('qq小程序'); +INSERT into reponsible(pid,bid)value +(1,1), +(1,2), +(2,2); +INSERT into reponsible2(pid,sid)value +(1,1), +(1,2), +(1,3), +(2,3); + + +``` + +## sql查询语句 + +```sql +-- 查看经理是哪个部门的经理 +SELECT m.name,s.bname FROM manager m RIGHT JOIN section s ON m.bid=s.bid; +-- 查看部门负责的项目 +SELECT p.pname,s.bname FROM reponsible r RIGHT JOIN porject p ON r.pid=p.pid RIGHT JOIN section s on r.bid=s.bid; +``` + +## 图片 + +![CDM](https://gitee.com/ChemuWare/gstxmm/raw/master/photo/202409080009819.png) + +![PDM](https://gitee.com/ChemuWare/gstxmm/raw/master/photo/202409080009923.png)![LDM](https://gitee.com/ChemuWare/gstxmm/raw/master/photo/202409080009463.png) \ No newline at end of file diff --git "a/\351\231\210\346\231\272\345\256\217/20240907\347\254\224\350\256\260.md" "b/\351\231\210\346\231\272\345\256\217/20240907\347\254\224\350\256\260.md" new file mode 100644 index 0000000000000000000000000000000000000000..96be38fd4c9b7bac3945acdb6763b71503ec8ee3 --- /dev/null +++ "b/\351\231\210\346\231\272\345\256\217/20240907\347\254\224\350\256\260.md" @@ -0,0 +1,16 @@ +## 图床 + +1. gitee当图床:病床,矿床,床是一个容器,图床一般指网络某个云服务。可用来存放图片,并通过url访问这上图片, + 1. 新建仓库,用来存图片 + 2. 获取私人令牌 +2. 安装picgo + 1. 上网搜picgo并下载 + 2. 安装gitee uploader的插件 + 3. 下载node.js +3. 配置typroa使用picgo + +![image-20240908001158562](https://gitee.com/ChemuWare/gstxmm/raw/master/photo/202409080011632.png) + +4.配置typora图像设置 + +5.上传笔记到gitee(1.git add . 2.git commit -m 'test' 3.git push) \ No newline at end of file diff --git "a/\351\231\210\346\231\272\345\256\217/CDM.png" "b/\351\231\210\346\231\272\345\256\217/CDM.png" deleted file mode 100644 index c13933f4aa3bf796f4ea8e69ddca8fbbc3b32fe9..0000000000000000000000000000000000000000 Binary files "a/\351\231\210\346\231\272\345\256\217/CDM.png" and /dev/null differ diff --git "a/\351\231\210\346\231\272\345\256\217/LDM.png" "b/\351\231\210\346\231\272\345\256\217/LDM.png" deleted file mode 100644 index 4bcdc547c954fde3b748e3fec233840b8b7b0285..0000000000000000000000000000000000000000 Binary files "a/\351\231\210\346\231\272\345\256\217/LDM.png" and /dev/null differ diff --git "a/\351\231\210\346\231\272\345\256\217/PDM.png" "b/\351\231\210\346\231\272\345\256\217/PDM.png" deleted file mode 100644 index b636748f7806c11fbb8c4465f99c642626c6259b..0000000000000000000000000000000000000000 Binary files "a/\351\231\210\346\231\272\345\256\217/PDM.png" and /dev/null differ diff --git "a/\351\231\210\346\231\272\345\256\217/\347\256\200\345\215\225\346\237\245\350\257\242.md" "b/\351\231\210\346\231\272\345\256\217/\347\256\200\345\215\225\346\237\245\350\257\242.md" deleted file mode 100644 index 395c9c1b851ecfad73866f1585463f2fad79f0fc..0000000000000000000000000000000000000000 --- "a/\351\231\210\346\231\272\345\256\217/\347\256\200\345\215\225\346\237\245\350\257\242.md" +++ /dev/null @@ -1,4 +0,0 @@ --- 查看经理是哪个部门的经理 -SELECT m.name,s.bname FROM manager m RIGHT JOIN section s ON m.bid=s.bid; --- 查看部门负责的项目 -SELECT p.pname,s.bname FROM reponsible r RIGHT JOIN porject p ON r.pid=p.pid RIGHT JOIN section s on r.bid=s.bid; \ No newline at end of file diff --git "a/\351\231\210\346\231\272\345\256\217/\347\256\241\347\220\206\347\263\273\347\273\237.sql" "b/\351\231\210\346\231\272\345\256\217/\347\256\241\347\220\206\347\263\273\347\273\237.sql" deleted file mode 100644 index 18d67c8561f0da4f41ca6d73698dcfa7d021d3a9..0000000000000000000000000000000000000000 --- "a/\351\231\210\346\231\272\345\256\217/\347\256\241\347\220\206\347\263\273\347\273\237.sql" +++ /dev/null @@ -1,119 +0,0 @@ -/*==============================================================*/ -/* DBMS name: MySQL 5.0 */ -/* Created on: 2024/9/4 20:42:42 */ -/*==============================================================*/ - -DROP DATABASE IF EXISTS glxt; -CREATE DATABASE glxt CHARACTER SET utf8; -use glxt; - -drop table if exists reponsible2; - -drop table if exists manager; - -drop table if exists porject; - -drop table if exists reponsible; - -drop table if exists section; - -drop table if exists staff; - - -/*==============================================================*/ -/* Table: reponsible2 */ -/*==============================================================*/ -create table reponsible2 -( - did int primary key auto_increment not null, - pid int not null, - sid int not null -); - -/*==============================================================*/ -/* Table: manager */ -/*==============================================================*/ -create table manager -( - id int primary key auto_increment not null, - bid int, - name varchar(5) -); - -/*==============================================================*/ -/* Table: porject */ -/*==============================================================*/ -create table porject -( - pid int primary key auto_increment not null, - pname varchar(255) -); - -/*==============================================================*/ -/* Table: reponsible */ -/*==============================================================*/ -create table reponsible -( - cid int primary key auto_increment not null, - pid int not null, - bid int not null -); - -/*==============================================================*/ -/* Table: section */ -/*==============================================================*/ -create table section -( - bid int primary key auto_increment not null, - bname varchar(255) -); - -/*==============================================================*/ -/* Table: staff */ -/*==============================================================*/ -create table staff -( - sid int primary key auto_increment not null, - bid int not null, - sname varchar(5), - sphone int -); - -alter table reponsible2 add constraint FK_f1 foreign key (pid) - references porject (pid) on delete restrict on update restrict; - -alter table reponsible2 add constraint FK_f2 foreign key (sid) - references staff (sid) on delete restrict on update restrict; - -alter table manager add constraint FK_gl foreign key (bid) - references section (bid) on delete restrict on update restrict; - -alter table reponsible add constraint FK_reponsible foreign key (pid) - references porject (pid) on delete restrict on update restrict; - -alter table reponsible add constraint FK_reponsible2 foreign key (bid) - references section (bid) on delete restrict on update restrict; - -alter table staff add constraint FK_life foreign key (bid) - references section (bid) on delete restrict on update restrict; -INSERT into section(bname)value -('前端'), -('后端'); -INSERT into manager(bid,name)VALUES(1,'李华'),(2,'肖康');INSERT into staff(bid,sname,sphone)VALUES -(1,'张三',10000), -(1,'李四',10086), -(2,'王五',10001) -; -INSERT into porject(pname)value -('微信小程序'), -('qq小程序'); -INSERT into reponsible(pid,bid)value -(1,1), -(1,2), -(2,2); -INSERT into reponsible2(pid,sid)value -(1,1), -(1,2), -(1,3), -(2,3); -