diff --git "a/52 \347\216\213\345\217\221\346\247\220/\344\271\235\346\234\2109 \345\217\267.md" "b/52 \347\216\213\345\217\221\346\247\220/\344\271\235\346\234\2109 \345\217\267.md" new file mode 100644 index 0000000000000000000000000000000000000000..31f171cbf0aa4fed86e35b7b7b43e56ff6b9b0a4 --- /dev/null +++ "b/52 \347\216\213\345\217\221\346\247\220/\344\271\235\346\234\2109 \345\217\267.md" @@ -0,0 +1,106 @@ +```sql + +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023/9/10 22:21:34 */ +/*==============================================================*/ + + +drop table if exists Borrowing; + +drop table if exists UserId; + +drop table if exists book; + +drop table if exists dengji; + +drop table if exists jiyie; + +drop table if exists "return"; + +/*==============================================================*/ +/* Table: Borrowing */ +/*==============================================================*/ +create table Borrowing +( + brtime char(10) not null, + userid int(10) not null auto_increment, + username char(6) not null, + returntime date not null, + bokname char(5) not null, + bokid int(10) not null auto_increment, + primary key (userid, bokid) +); + +/*==============================================================*/ +/* Table: UserId */ +/*==============================================================*/ +create table UserId +( + user_id int(10) not null auto_increment, + user_name char(5) not null, + user_password char(6) not null, + primary key (user_id) +); + +/*==============================================================*/ +/* Table: book */ +/*==============================================================*/ +create table book +( + bk_id int(10) not null auto_increment, + bk_name char(10) not null, + primary key (bk_id) +); + +/*==============================================================*/ +/* Table: dengji */ +/*==============================================================*/ +create table dengji +( + bk_id int not null, + user_id int not null, + primary key (bk_id, user_id) +); + +/*==============================================================*/ +/* Table: jiyie */ +/*==============================================================*/ +create table jiyie +( + userid int not null, + bokid int not null, + user_id int not null, + primary key (userid, bokid, user_id) +); + +/*==============================================================*/ +/* Table: "return" */ +/*==============================================================*/ +create table "return" +( + userid int not null, + bokid int not null, + bk_id int not null, + primary key (userid, bokid, bk_id) +); + +alter table dengji add constraint FK_dengji foreign key (bk_id) + references book (bk_id) on delete restrict on update restrict; + +alter table dengji add constraint FK_dengji2 foreign key (user_id) + references UserId (user_id) on delete restrict on update restrict; + +alter table jiyie add constraint FK_jiyie foreign key (userid, bokid) + references Borrowing (userid, bokid) on delete restrict on update restrict; + +alter table jiyie add constraint FK_jiyie2 foreign key (user_id) + references UserId (user_id) on delete restrict on update restrict; + +alter table "return" add constraint FK_return foreign key (userid, bokid) + references Borrowing (userid, bokid) on delete restrict on update restrict; + +alter table "return" add constraint FK_return2 foreign key (bk_id) + references book (bk_id) on delete restrict on update restrict; +``` +