diff --git "a/\345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237\346\234\200\347\273\210\347\211\210.md" "b/\345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237\346\234\200\347\273\210\347\211\210.md" new file mode 100644 index 0000000000000000000000000000000000000000..361c0f55843fed7a814aaa391a40cfa3777b4c47 --- /dev/null +++ "b/\345\233\276\344\271\246\347\256\241\347\220\206\347\263\273\347\273\237\346\234\200\347\273\210\347\211\210.md" @@ -0,0 +1,283 @@ +```mysql +-- 创建数据库 +create database t_books charset utf8; +-- 使用数据库 +use t_books; + + + +/*==============================================================*/ +/* DBMS name: MySQL 5.0 */ +/* Created on: 2023-09-11 20:27:33 */ +/*==============================================================*/ + + +drop table if exists bookinfo;-- 书籍具体信息表 + +drop table if exists borrow;-- 借阅信息表 + +drop table if exists floormassage;-- 楼层信息表 + +drop table if exists gett;-- 接收人 + +drop table if exists library;-- 图书馆表 + +drop table if exists put;-- 放置图书 + +drop table if exists return_book;-- 归还信息表 + +drop table if exists user;-- 用户登录表 + +drop table if exists userinfo;-- 用户信息表 + +drop table if exists work;-- 管理员信息表 + +/*==============================================================*/ +/* Table: bookinfo */ +/*==============================================================*/ + +-- 书籍具体信息表 +create table bookinfo +( + book_ID int not null auto_increment, -- 书籍编号 + ID int not null, -- 楼层编号 + book_name char(20) not null, -- 书籍名称 + author varchar(15) not null, -- 书籍作者 + publish date not null, -- 出版时间 + book_price numeric(10,2) not null, -- 书籍价格 + primary key (book_ID) +); + +/*==============================================================*/ +/* Table: borrow */ +/*==============================================================*/ + +-- 借阅信息表 +create table borrow +( + borrow_ID int not null auto_increment, -- 借阅编号 + book_ID int not null, -- 书籍编号 + borrow_date date not null, -- 借阅时间 + return_date date not null, -- 归还时间 + primary key (borrow_ID) +); + +/*==============================================================*/ +/* Table: floormassage */ +/*==============================================================*/ + +-- 楼层信息表 +create table floormassage +( + ID int not null auto_increment, -- 楼层编号 + lib_ID int not null, -- 图书馆编号 + floor char(3) not null, -- 楼层 + shelf_ID int not null, -- 书架编号 + linenum int not null, -- 行号 + type char(10) not null, -- 类型 + primary key (ID) +); + +/*==============================================================*/ +/* Table: get */ +/*==============================================================*/ + +-- 接收人 +create table gett +( + worker_ID int not null, -- 管理员编号 + return_ID int not null, -- 归还编号 + primary key (worker_ID, return_ID) +); + +/*==============================================================*/ +/* Table: library */ +/*==============================================================*/ + +-- 图书馆表 +create table library +( + lib_ID int not null auto_increment, -- 图书馆编号 + user_ID int not null, -- 用户编号 + lib_name varchar(10) not null, -- 图书馆名称 + primary key (lib_ID) +); + +/*==============================================================*/ +/* Table: put */ +/*==============================================================*/ + +-- 放置图书 +create table put +( + lib_ID int not null, -- 楼层编号 + worker_ID int not null, -- 管理员编号 + primary key (lib_ID, worker_ID) +); + +/*==============================================================*/ +/* Table: "return" */ +/*==============================================================*/ + +-- 归还信息表 +create table return_book +( + return_ID int not null auto_increment, -- 归还编号 + user_ID int not null, -- 用户编号 + return_date date not null, -- 归还时间 + primary key (return_ID) +); + +/*==============================================================*/ +/* Table: user */ +/*==============================================================*/ + +-- 用户登录表 +create table user +( + user_ID int not null auto_increment, -- 用户编号 + user_name varchar(5) not null, -- 用户姓名 + password varchar(10) not null, -- 密码 + primary key (user_ID) +); + +/*==============================================================*/ +/* Table: userinfo */ +/*==============================================================*/ + +-- 用户信息表 +create table userinfo +( + userinfo_ID int not null auto_increment, -- 用户信息编号 + user_ID int not null, -- 用户编号 + userinfo_name varchar(6) not null, -- 用户姓名 + userinfo_sex char(1) not null, -- 用户性别 + college char(10) not null, -- 学院 + major char(15) not null, -- 专业 + grade char(20) not null, -- 年级 + class char(20) not null, -- 班级 + user_tel char(15) not null, -- 用户电话 + primary key (userinfo_ID) +); + +/*==============================================================*/ +/* Table: work */ +/*==============================================================*/ + +-- 管理员信息表 +create table work +( + worker_ID int not null auto_increment, -- 员工编号 + worker_name varchar(5) not null, -- 员工姓名 + worker_sex char(1) not null, -- 员工性别 + worker_tel char(12) not null, -- 员工电话 + worker_salary int not null, -- 员工工资 + primary key (worker_ID) +); + +alter table bookinfo add constraint FK_check_book foreign key (ID) + references floormassage (ID) on delete restrict on update restrict; + +alter table borrow add constraint FK_borrow foreign key (book_ID) + references bookinfo (book_ID) on delete restrict on update restrict; + +alter table floormassage add constraint FK_check_floor foreign key (lib_ID) + references library (lib_ID) on delete restrict on update restrict; + +alter table gett add constraint FK_get foreign key (worker_ID) + references work (worker_ID) on delete restrict on update restrict; + +alter table gett add constraint FK_get2 foreign key (return_ID) + references return_book (return_ID) on delete restrict on update restrict; + +alter table library add constraint FK_check foreign key (user_ID) + references user (user_ID) on delete restrict on update restrict; + +alter table put add constraint FK_put foreign key (lib_ID) + references library (lib_ID) on delete restrict on update restrict; + +alter table put add constraint FK_put2 foreign key (worker_ID) + references work (worker_ID) on delete restrict on update restrict; + +alter table return_book add constraint FK_return foreign key (user_ID) + references user (user_ID) on delete restrict on update restrict; + +alter table userinfo add constraint FK_information foreign key (user_ID) + references user (user_ID) on delete restrict on update restrict; + + ### 用户登录 + +insert into user values -- 用户登录 +(001,'小梅','123'), +(002,'小晶','456'), +(003,'小芳','789'); + + + ### 用户信息表 +insert into userinfo values +(101,001,'韩梅梅','女','软件工程学院','前端','22级','1班','1234567892'), +(102,002,'郭晶晶','女','软件工程学院','后端','22级','2班','2345678925'), +(103,003,'李静芳','女','软件工程学院','新媒体','22级','10班','1234567894'); + + +### 图书馆信息表 +insert into library values +(201,001,'北京市图书馆'), +(202,002,'龙岩市图书馆'), +(203,003,'厦门市图书馆'); + +### 楼层信息表 +insert into floormassage values +(301,201,'四楼',337,1,'外国著作'), +(302,202,'六楼',338,2,'文学经典'), +(303,203,'五楼',339,3,'仙侠类'); + +### 书籍具体信息表 +insert into bookinfo values -- 图书信息 +(401,301,'战争与和平','列夫托尔斯泰','1869-6-6',45), +(402,302,'活着','余华','1992-12-2',60), +(403,303,'花千骨','果果','2018-12-31',80.8); + + + + + +### 借阅信息表 +insert into borrow values -- 图书借阅 +(501,401,'2023-04-16','2023-05-16'), +(502,402,'2023-04-16','2023-05-16'), +(503,403,'2023-04-16','2023-05-16'); + + + + +### 归还信息表 +insert into return_book values -- 归还图书 +(601,001,'2023-04-25'), +(602,002,'2023-05-10'), +(603,003,'2023-05-16'); + + + +### 管理员 +insert into work values +(701,'张三','男','1594628347',5000), +(702,'李四','男','1569821347',4000), +(703,'李雪','女','1634957612',3000); + + +-- 接受表 +insert into gett values +(701,601), +(702,602), +(703,603); + +-- 放置表 +insert into put values +(201,701), +(202,702), +(203,703); + + +``` +