From 657fb68baf1d11246d0c8f49283d22b046736fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E9=9B=AA=E7=90=BC?= <3403255493@qq.com> Date: Fri, 8 Sep 2023 11:54:18 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E7=94=B0=E9=9B=AA=E7=90=BC=E7=9A=84?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20230907 \347\254\224\350\256\260.md.md" | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 "35 \347\224\260\351\233\252\347\220\274/20230907 \347\254\224\350\256\260.md.md" diff --git "a/35 \347\224\260\351\233\252\347\220\274/20230907 \347\254\224\350\256\260.md.md" "b/35 \347\224\260\351\233\252\347\220\274/20230907 \347\254\224\350\256\260.md.md" new file mode 100644 index 0000000..fb7ae62 --- /dev/null +++ "b/35 \347\224\260\351\233\252\347\220\274/20230907 \347\254\224\350\256\260.md.md" @@ -0,0 +1,9 @@ +# 笔记: + +数据库设计的三大范式: + +1.第一范式:每个属性,也就是字段要求不可分割,也就要求有原子性 + +2.第二范式:在满足第一范式的基础上,要求非主键字段要完全依赖主键(有联合主键时,非主键要同时完全依赖这两个主键,而不能部分依赖) + +3.第三范式:在满足第二范式时的基础上,要求非主键子段要直接依赖于主键 \ No newline at end of file -- Gitee From 0fcf00e1c3d22f738ffcc386796bf2d49f815eef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E9=9B=AA=E7=90=BC?= <3403255493@qq.com> Date: Sun, 10 Sep 2023 22:51:06 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=94=B0=E9=9B=AA=E7=90=BC=E7=9A=84?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\347\220\206\347\263\273\347\273\237.txt" | 194 ++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 "35 \347\224\260\351\233\252\347\220\274/20230910 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.txt" diff --git "a/35 \347\224\260\351\233\252\347\220\274/20230910 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.txt" "b/35 \347\224\260\351\233\252\347\220\274/20230910 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.txt" new file mode 100644 index 0000000..ea10775 --- /dev/null +++ "b/35 \347\224\260\351\233\252\347\220\274/20230910 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.txt" @@ -0,0 +1,194 @@ +# 笔记 +建模 + +1概念模型:CDM ER图、人类角度 + +2.逻辑模型:LDM 计算机 + +3.物理模型:PDM 从具体数据库角度 + +4.生成DDL + +# 作业 + +```mysql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/9 13:52:45 */ +/*==============================================================*/ + + +CREATE DATABASE Book CHARSET utf8; +use Book; +drop table if exists book; + +drop table if exists borrow; + +drop table if exists giveBack; + +drop table if exists store; + +drop table if exists system; + +drop table if exists type; + +drop table if exists user; + +/*==============================================================*/ +/* Table: book */ +/*==============================================================*/ +create table book +( + b_id varchar(4) not null, + type_id int, + b_name varchar(8) not null, + b_writer varchar(8) not null, + b_press varchar(8) not null, + b_date varchar(12) not null, + b_price decimal(5,2) not null, + primary key (b_id) +); +INSERT INTO book VALUES +('001',1,'红楼梦','曹雪芹','人民文学出版社','2008年7月1日',51.5), +('002',2,'格林童话','格林兄弟','吉林美术出版社','2019年4月',38.9), +('003',3,'法医秦明','秦明','江苏文艺出版社','2020年10月',49.8); + + + +/*==============================================================*/ +/* Table: borrow */ +/*==============================================================*/ +create table borrow +( + borrow_id int not null auto_increment, + u_id int, + b_id varchar(4), + borrow_amout int not null, + borrow_date date not null, + borrow_time varchar(8) not null, + borrow_end date not null, + primary key (borrow_id) +); +INSERT INTO borrow VALUES +(1,1,'001',1,'2023-9-1','20天','2023-9-21'), +(2,3,'002',2,'2023-9-2','15天','2023-9-17'), +(3,2,'003',3,'2023-9-3','25天','2023-9-28'); + +/*==============================================================*/ +/* Table: giveBack */ +/*==============================================================*/ +create table giveBack +( + giveBack_id int not null auto_increment, + u_id int, + b_id varchar(4), + giveBack_amount int not null, + giveBack_date date not null, + primary key (giveBack_id) +); +INSERT into giveBack VALUES +(1,2,'001',1,'2023-9-20'), +(2,1,'003',3,'2023-9-25'), +(3,3,'002',4,'2023-9-30'); + +/*==============================================================*/ +/* Table: store */ +/*==============================================================*/ +create table store +( + s_id int not null auto_increment, + b_id varchar(4), + s_floor int not null, + s_area varchar(4) not null, + s_pressmark varchar(4) not null, + s_tier int not null, + primary key (s_id) +); +INSERT INTO store VALUES +(null,'001',3,'1区','01',2), +(null,'003',4,'2区','02',3), +(null,'002',5,'3区','03',4); + + +/*==============================================================*/ +/* Table: system */ +/*==============================================================*/ +create table system +( + system_id int not null auto_increment, + u_id int, + system_name varchar(12) not null, + system_amount int not null, + system_time varchar(8) not null, + system_price decimal not null, + primary key (system_id) +); +INSERT INTO system VALUES +(1,3,'普通会员',20,'1个月',30), +(2,1,'vip会员',35,'2个月',55), +(3,2,'svip会员',20,'3个月',75); + + + +/*==============================================================*/ +/* Table: type */ +/*==============================================================*/ +create table type +( + type_id int not null, + b_id varchar(4), + type_name varchar(8) not null, + primary key (type_id) +); +insert into type VALUES +(1,'001','文学类'), +(2,'002','少儿类'), +(3,'003','悬疑类'); + + +/*==============================================================*/ +/* Table: user */ +/*==============================================================*/ +create table user +( + u_id int not null auto_increment, + u_name varchar(4) not null, + u_sex varchar(4) not null, + u_age int not null, + u_tel varchar(12) not null, + primary key (u_id) +); +INSERT into user VALUES +(1,'张三','男',18,'15107465789'), +(2,'李四','女',19,'18234567891'), +(3,'王五','男',18,'13342849002'); + + + +alter table book add constraint FK_Relationship_4 foreign key (type_id) + references type (type_id) on delete restrict on update restrict; + +alter table borrow add constraint FK_ި˩ foreign key (b_id) + references book (b_id) on delete restrict on update restrict; + +alter table borrow add constraint FK_ި˩ԃۧ foreign key (u_id) + references user (u_id) on delete restrict on update restrict; + +alter table giveBack add constraint FK_Relationship_3 foreign key (u_id) + references user (u_id) on delete restrict on update restrict; + +alter table giveBack add constraint FK_۹˩ foreign key (b_id) + references book (b_id) on delete restrict on update restrict; + +alter table store add constraint FK_Relationship_1 foreign key (b_id) + references book (b_id) on delete restrict on update restrict; + +alter table system add constraint FK_Relationship_5 foreign key (u_id) + references user (u_id) on delete restrict on update restrict; + +alter table type add constraint FK_Relationship_2 foreign key (b_id) + references book (b_id) on delete restrict on update restrict; +select * from user; +select * from borrow; +select * from user,borrow where user.u_id = borrow.u_id; +``` \ No newline at end of file -- Gitee From 966a711584544cfcfbaf39edd6b46be2ad417fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B0=E9=9B=AA=E7=90=BC?= <11785247+tian-xueqiong@user.noreply.gitee.com> Date: Sun, 10 Sep 2023 14:52:41 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E9=87=8D=E5=91=BD=E5=90=8D=2035=20?= =?UTF-8?q?=E7=94=B0=E9=9B=AA=E7=90=BC/20230910=20=E5=9B=BE=E4=B9=A6?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=B3=BB=E7=BB=9F.txt=20=E4=B8=BA=2035=20?= =?UTF-8?q?=E7=94=B0=E9=9B=AA=E7=90=BC/20230910=20=E5=9B=BE=E4=B9=A6?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=B3=BB=E7=BB=9F.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...44\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "35 \347\224\260\351\233\252\347\220\274/20230910 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.txt" => "35 \347\224\260\351\233\252\347\220\274/20230910 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" (100%) diff --git "a/35 \347\224\260\351\233\252\347\220\274/20230910 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.txt" "b/35 \347\224\260\351\233\252\347\220\274/20230910 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" similarity index 100% rename from "35 \347\224\260\351\233\252\347\220\274/20230910 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.txt" rename to "35 \347\224\260\351\233\252\347\220\274/20230910 \345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" -- Gitee