From b2ae6c1b7a304a252958049e5b59716c776cbc4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=AB=E7=BB=A7=E5=91=A8?= Date: Mon, 11 Sep 2023 13:11:38 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E4=B9=A6=E7=AE=A1=E7=90=86=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 闫继周 --- ...41\347\220\206\347\263\273\347\273\237.md" | 260 ++++++++++++++++++ ...02\350\257\276\347\254\224\350\256\260.md" | 9 + ...02\350\257\276\347\254\224\350\256\260.md" | 25 ++ 3 files changed, 294 insertions(+) create mode 100644 "\345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" create mode 100644 "\347\254\254\344\270\211\350\212\202\350\257\276\347\254\224\350\256\260.md" create mode 100644 "\347\254\254\345\233\233\350\212\202\350\257\276\347\254\224\350\256\260.md" diff --git "a/\345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" "b/\345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" new file mode 100644 index 0000000..b3938c6 --- /dev/null +++ "b/\345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237.md" @@ -0,0 +1,260 @@ +if exists(select 1 from sys.sysforeignkey where role='FK_BORROW2_BORROW_LIBRARY') then + alter table Borrow2 + delete foreign key FK_BORROW2_BORROW_LIBRARY +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_BORROW2_BORROW2_BORROW') then + alter table Borrow2 + delete foreign key FK_BORROW2_BORROW2_BORROW +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_MANAGE_MANAGE_LIBRARY') then + alter table manage + delete foreign key FK_MANAGE_MANAGE_LIBRARY +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_MANAGE_MANAGE2_WORKING') then + alter table manage + delete foreign key FK_MANAGE_MANAGE2_WORKING +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_SERVE_SERVE_WORKING') then + alter table serve + delete foreign key FK_SERVE_SERVE_WORKING +end if; + +if exists(select 1 from sys.sysforeignkey where role='FK_SERVE_SERVE2_BORROW') then + alter table serve + delete foreign key FK_SERVE_SERVE2_BORROW +end if; + +drop index if exists Borrow.Borrow_PK; + +drop table if exists Borrow; + +drop index if exists Borrow2.Borrow2_FK; + +drop index if exists Borrow2.Borrow_FK; + +drop index if exists Borrow2.Borrow2_PK; + +drop table if exists Borrow2; + +drop index if exists library.library_PK; + +drop table if exists library; + +drop index if exists manage.manage2_FK; + +drop index if exists manage.manage_FK; + +drop index if exists manage.manage_PK; + +drop table if exists manage; + +drop index if exists serve.serve_FK; + +drop index if exists serve.serve2_FK; + +drop index if exists serve.serve_PK; + +drop table if exists serve; + +drop index if exists "working personnel"."working personnel_PK"; + +drop table if exists "working personnel"; + +/*==============================================================*/ +/* Table: Borrow */ +/*==============================================================*/ +create table Borrow +( + Bor_id integer not null, + Bor_name varchar(10) not null, + Bor_level integer not null, + Bor_blacklist varchar(10) not null, + constraint PK_BORROW primary key (Bor_id) +); + +/*==============================================================*/ +/* Index: Borrow_PK */ +/*==============================================================*/ +create unique index Borrow_PK on Borrow ( +Bor_id ASC +); + +/*==============================================================*/ +/* Table: Borrow2 */ +/*==============================================================*/ +create table Borrow2 +( + lib_id integer not null, + Bor_id integer not null, + situation char(4) not null, + constraint PK_BORROW2 primary key (lib_id, Bor_id) +); + +/*==============================================================*/ +/* Index: Borrow2_PK */ +/*==============================================================*/ +create unique index Borrow2_PK on Borrow2 ( +lib_id ASC, +Bor_id ASC +); + +/*==============================================================*/ +/* Index: Borrow_FK */ +/*==============================================================*/ +create index Borrow_FK on Borrow2 ( +lib_id ASC +); + +/*==============================================================*/ +/* Index: Borrow2_FK */ +/*==============================================================*/ +create index Borrow2_FK on Borrow2 ( +Bor_id ASC +); + +/*==============================================================*/ +/* Table: library */ +/*==============================================================*/ +create table library +( + lib_id integer not null, + lib_name varchar(20) not null, + lib_state varchar(3) not null, + lib_author varchar(10) not null, + lib_publish varchar(20) not null, + lib_classes integer not null, + constraint PK_LIBRARY primary key (lib_id) +); + +/*==============================================================*/ +/* Index: library_PK */ +/*==============================================================*/ +create unique index library_PK on library ( +lib_id ASC +); + +/*==============================================================*/ +/* Table: manage */ +/*==============================================================*/ +create table manage +( + lib_id integer not null, + wor_id integer not null, + lib_state varchar(2) not null, + constraint PK_MANAGE primary key (lib_id, wor_id) +); + +/*==============================================================*/ +/* Index: manage_PK */ +/*==============================================================*/ +create unique index manage_PK on manage ( +lib_id ASC, +wor_id ASC +); + +/*==============================================================*/ +/* Index: manage_FK */ +/*==============================================================*/ +create index manage_FK on manage ( +lib_id ASC +); + +/*==============================================================*/ +/* Index: manage2_FK */ +/*==============================================================*/ +create index manage2_FK on manage ( +wor_id ASC +); + +/*==============================================================*/ +/* Table: serve */ +/*==============================================================*/ +create table serve +( + wor_id integer not null, + Bor_id integer not null, + constraint PK_SERVE primary key (wor_id, Bor_id) +); + +/*==============================================================*/ +/* Index: serve_PK */ +/*==============================================================*/ +create unique index serve_PK on serve ( +wor_id ASC, +Bor_id ASC +); + +/*==============================================================*/ +/* Index: serve2_FK */ +/*==============================================================*/ +create index serve2_FK on serve ( +Bor_id ASC +); + +/*==============================================================*/ +/* Index: serve_FK */ +/*==============================================================*/ +create index serve_FK on serve ( +wor_id ASC +); + +/*==============================================================*/ +/* Table: "working personnel" */ +/*==============================================================*/ +create table "working personnel" +( + wor_id integer not null, + wor_name varchar(4) not null, + wor_position varchar(10) not null, + wor_range varchar(20) not null, + wor_state varchar(4) not null, + constraint "PK_WORKING PERSONNEL" primary key (wor_id) +); + +/*==============================================================*/ +/* Index: "working personnel_PK" */ +/*==============================================================*/ +create unique index "working personnel_PK" on "working personnel" ( +wor_id ASC +); + +alter table Borrow2 + add constraint FK_BORROW2_BORROW_LIBRARY foreign key (lib_id) + references library (lib_id) + on update restrict + on delete restrict; + +alter table Borrow2 + add constraint FK_BORROW2_BORROW2_BORROW foreign key (Bor_id) + references Borrow (Bor_id) + on update restrict + on delete restrict; + +alter table manage + add constraint FK_MANAGE_MANAGE_LIBRARY foreign key (lib_id) + references library (lib_id) + on update restrict + on delete restrict; + +alter table manage + add constraint FK_MANAGE_MANAGE2_WORKING foreign key (wor_id) + references "working personnel" (wor_id) + on update restrict + on delete restrict; + +alter table serve + add constraint FK_SERVE_SERVE_WORKING foreign key (wor_id) + references "working personnel" (wor_id) + on update restrict + on delete restrict; + +alter table serve + add constraint FK_SERVE_SERVE2_BORROW foreign key (Bor_id) + references Borrow (Bor_id) + on update restrict + on delete restrict; +``` \ No newline at end of file diff --git "a/\347\254\254\344\270\211\350\212\202\350\257\276\347\254\224\350\256\260.md" "b/\347\254\254\344\270\211\350\212\202\350\257\276\347\254\224\350\256\260.md" new file mode 100644 index 0000000..3e44f60 --- /dev/null +++ "b/\347\254\254\344\270\211\350\212\202\350\257\276\347\254\224\350\256\260.md" @@ -0,0 +1,9 @@ +数据库的范式: + +1.第一范式:要求字段的内容,不可再分割,为的是保证数据的原子性。 + +2.第二范式:要求在满足第一范式的基础上,要求非主键字段要完全依赖主键,(非主键要依赖整个联合主键)而不能只依赖部分 + +3.第三范式:满足第二范式的前提上,要求非主键要直接依赖主键 + +注意:实际开发不会完全按照范式来设计,因为需求不一样,有时会故意反范式 \ No newline at end of file diff --git "a/\347\254\254\345\233\233\350\212\202\350\257\276\347\254\224\350\256\260.md" "b/\347\254\254\345\233\233\350\212\202\350\257\276\347\254\224\350\256\260.md" new file mode 100644 index 0000000..49f3ea4 --- /dev/null +++ "b/\347\254\254\345\233\233\350\212\202\350\257\276\347\254\224\350\256\260.md" @@ -0,0 +1,25 @@ +Visio制作ER图的一个软件: + +一个软件:power Designer + +第一步:创建概念模型(类似ER图)CDM(以用户的角度) + +第二步:转换成逻辑模型LDM (以计算机的角度) + +第三步:转换成物理模型 (以数据库角度) + + + +数据库设计步骤: + +1.需求分析 + +2.ER图 + +3.逻辑结构设计 + +4.物理模型设计 + +5.数据库的实施 + +6.数据库的维护 \ No newline at end of file -- Gitee