From a582657ff488f6a962ade0f885acdfc79eb47112 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=8E=E5=86=A0=E5=AE=87?= Date: Sun, 10 Sep 2023 14:11:49 +0000 Subject: [PATCH] =?UTF-8?q?=E9=98=8E=E5=86=A0=E5=AE=87=E7=9A=84=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 阎冠宇 --- ...46\351\246\206\350\256\276\350\256\241.md" | 216 ++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 "34\351\230\216\345\206\240\345\256\207/20230908 \345\233\276\344\271\246\351\246\206\350\256\276\350\256\241.md" diff --git "a/34\351\230\216\345\206\240\345\256\207/20230908 \345\233\276\344\271\246\351\246\206\350\256\276\350\256\241.md" "b/34\351\230\216\345\206\240\345\256\207/20230908 \345\233\276\344\271\246\351\246\206\350\256\276\350\256\241.md" new file mode 100644 index 0000000..61a5ab2 --- /dev/null +++ "b/34\351\230\216\345\206\240\345\256\207/20230908 \345\233\276\344\271\246\351\246\206\350\256\276\350\256\241.md" @@ -0,0 +1,216 @@ +## 笔记 + +##### 设计数据库 + +1.概念模型 CDM + +2.逻辑模型 LDM + +3.物理模型 PDM + +4.生成DDL + + + +##### 使用软件PowerDesigner设计数据库 + + + +##### ER图三要素 + +1.visio 一种画流程图的软件 + +2.实体关系图 + +3.三要素 + +Ⅰ.实体:画矩形,写里面的实体的名称 + +Ⅱ.属性:椭圆或圆形,里面写属性名称,用线条与实体相连,如果是主属性名称下加下划线 + +Ⅲ.关系:用线条将两个实体相连,中间可以用菱形表示中间的关系 + + + +```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; +``` + -- Gitee