diff --git "a/57 \351\273\204\346\265\201\346\266\233/20230911 \345\233\276\344\271\246\351\246\206\346\225\260\346\215\256\345\272\223.md" "b/57 \351\273\204\346\265\201\346\266\233/20230911 \345\233\276\344\271\246\351\246\206\346\225\260\346\215\256\345\272\223.md" new file mode 100644 index 0000000000000000000000000000000000000000..357afa16e3dd5a6d9926ce32d50ace0ac8c87643 --- /dev/null +++ "b/57 \351\273\204\346\265\201\346\266\233/20230911 \345\233\276\344\271\246\351\246\206\346\225\260\346\215\256\345\272\223.md" @@ -0,0 +1,199 @@ +# 笔记 + +### powerDesigner + +​ 第一步:创建概念模型(类似ER图) CDM (用户角度) + +​ 第二步:转换成逻辑模型 LDM (计算机角度) + +​ 第三步:转换成物理模型 PDM (数据库角度) + +​ 第四步:生成DDL + +### 数据库设计步骤 + +​ 1.需求分析,了解要开发的系统的需求,明确数据和格式 + +​ 2.概念结构设计:将需求分析得到的抽象成概念模型,将ER图向关系模型转化 + +​ 3.逻辑结构设计:将概念结构转化成DBMS所支持的数据模型 + +​ 4.物理结构设计:将概念模型,转换成选定数据库管理系统需要的物理模型 + +​ 5.数据库实施:根据物理模型生成对应的DDL + +​ 6.数据库维护 + +# 作业 + +## 图书管理数据库 + +​ 图书馆:图书馆编号,馆名,地址,联系电话 + +​ 书架:书架编号,书籍类型 + +​ 图书管理员:图书管理员工号,姓名,年龄,性别 + +​ 系统管理员:系统管理员编号,姓名,年龄,性别 + +​ 图书:图书编号,书名,作者,价格 + +​ 出版社:出版社编号,出版社名 + +​ 读者:学号,姓名,性别,联系电话 + +​ ![image-20230911034830127](https://s2.loli.net/2023/09/11/g63zoXdP4JTHxyS.png) + +![image-20230911035634156](https://s2.loli.net/2023/09/11/DrnxFSBvH9y6Z2t.png) + +``` mysql +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/11 4:12:35 */ +/*==============================================================*/ +CREATE DATABASE tushu charset utf8; +use tushu; + +drop table if exists Books; + +drop table if exists Borrowing; + +drop table if exists administrator; + +drop table if exists bookshelf; + +drop table if exists librarian; + +drop table if exists library; + +drop table if exists publishing; + +drop table if exists reader; + +/*==============================================================*/ +/* Table: Books */ +/*==============================================================*/ + + +create table Books +( + Books_id int not null auto_increment, + publishing_id int not null, + bookshelf_id int not null, + librarian_id char(10) not null, + Books_name char(20) not null, + Books_author char(10) not null, + Books_Price decimal(5,2) not null, + primary key (Books_id) +); + +/*==============================================================*/ +/* Table: Borrowing */ +/*==============================================================*/ +create table Borrowing +( + Books_id int not null, + reader_id char(10) not null, + borrowing_time datetime not null, + borrowing_tim datetime, + primary key (Books_id, reader_id) +); + +/*==============================================================*/ +/* Table: administrator */ +/*==============================================================*/ +create table administrator +( + administrator_id char(10) not null, + administrator_name char(4) not null, + administrator_age char(2) not null, + administrator_sex char(1) not null, + primary key (administrator_id) +); + +/*==============================================================*/ +/* Table: bookshelf */ +/*==============================================================*/ +create table bookshelf +( + bookshelf_id int not null auto_increment, + library_id int not null, + bookshelf_type char(10) not null, + primary key (bookshelf_id) +); + +/*==============================================================*/ +/* Table: librarian */ +/*==============================================================*/ +create table librarian +( + librarian_id char(10) not null, + administrator_id char(10) not null, + librarian_name char(4) not null, + librarian_age char(2) not null, + librarian_sex char(1) not null, + primary key (librarian_id) +); + +/*==============================================================*/ +/* Table: library */ +/*==============================================================*/ +create table library +( + library_id int not null auto_increment, + library_name char(10) not null, + library_add varchar(255) not null, + library_tel char(11) not null, + primary key (library_id) +); + +/*==============================================================*/ +/* Table: publishing */ +/*==============================================================*/ +create table publishing +( + publishing_id int not null auto_increment, + publishing_name char(20) not null, + primary key (publishing_id) +); + +/*==============================================================*/ +/* Table: reader */ +/*==============================================================*/ +create table reader +( + reader_id char(10) not null, + administrator_id char(10) not null, + reader_name char(4) not null, + reader_sex char(1) not null, + reader_tel char(11) not null, + primary key (reader_id) +); + +alter table Books add constraint FK_have foreign key (bookshelf_id) + references bookshelf (bookshelf_id) on delete restrict on update restrict; + +alter table Books add constraint FK_manage foreign key (librarian_id) + references librarian (librarian_id) on delete restrict on update restrict; + +alter table Books add constraint FK_publication foreign key (publishing_id) + references publishing (publishing_id) on delete restrict on update restrict; + +alter table Borrowing add constraint FK_Borrowing foreign key (Books_id) + references Books (Books_id) on delete restrict on update restrict; + +alter table Borrowing add constraint FK_Borrowing2 foreign key (reader_id) + references reader (reader_id) on delete restrict on update restrict; + +alter table bookshelf add constraint FK_possess foreign key (library_id) + references library (library_id) on delete restrict on update restrict; + +alter table librarian add constraint "FK_Manage information" foreign key (administrator_id) + references administrator (administrator_id) on delete restrict on update restrict; + +alter table reader add constraint "FK_Manage reader" foreign key (administrator_id) + references administrator (administrator_id) on delete restrict on update restrict; + + +``` +