会员(会员ID、姓名、联系方式、会员类型、会费) 书籍(书籍ID、书名、作者、出版社、分类、数量、价格) 借阅(借阅ID、会员ID、书籍ID、借阅日期、归还日期、应还日期、实还日期、借阅状态) 收入(收入ID、会员ID、收入类型、金额、收入日期)写出其对应的逻辑结构设计利用mysql的相关命令创建,并利用相关mysql语句达成1.添加、修改、删除会员信息 2.添加、修改、删除书籍信息 3.查询、借阅、归还书籍 4.查询借阅信息、收入信息 5.书籍检索 6.计算罚款
时间: 2023-08-15 22:08:56 浏览: 166
好的,以下是对应的逻辑结构设计:
1. 会员表:Member(memberID, name, contact, type, fee)
- memberID: int,主键,会员ID
- name: varchar,会员姓名
- contact: varchar,联系方式
- type: varchar,会员类型
- fee: decimal,会费
2. 书籍表:Book(bookID, title, author, publisher, category, quantity, price)
- bookID: int,主键,书籍ID
- title: varchar,书名
- author: varchar,作者
- publisher: varchar,出版社
- category: varchar,分类
- quantity: int,数量
- price: decimal,价格
3. 借阅表:Borrow(borrowID, memberID, bookID, borrowDate, returnDate, dueDate, actualReturnDate, status)
- borrowID: int,主键,借阅ID
- memberID: int,外键,会员ID
- bookID: int,外键,书籍ID
- borrowDate: date,借阅日期
- returnDate: date,归还日期
- dueDate: date,应还日期
- actualReturnDate: date,实还日期
- status: varchar,借阅状态
4. 收入表:Income(incomeID, memberID, type, amount, date)
- incomeID: int,主键,收入ID
- memberID: int,外键,会员ID
- type: varchar,收入类型
- amount: decimal,金额
- date: date,收入日期
利用mysql的相关命令创建表:
CREATE TABLE Member (
memberID INT PRIMARY KEY,
name VARCHAR(50),
contact VARCHAR(50),
type VARCHAR(50),
fee DECIMAL(10,2)
);
CREATE TABLE Book (
bookID INT PRIMARY KEY,
title VARCHAR(100),
author VARCHAR(50),
publisher VARCHAR(50),
category VARCHAR(50),
quantity INT,
price DECIMAL(10,2)
);
CREATE TABLE Borrow (
borrowID INT PRIMARY KEY,
memberID INT,
bookID INT,
borrowDate DATE,
returnDate DATE,
dueDate DATE,
actualReturnDate DATE,
status VARCHAR(50),
FOREIGN KEY (memberID) REFERENCES Member(memberID),
FOREIGN KEY (bookID) REFERENCES Book(bookID)
);
CREATE TABLE Income (
incomeID INT PRIMARY KEY,
memberID INT,
type VARCHAR(50),
amount DECIMAL(10,2),
date DATE,
FOREIGN KEY (memberID) REFERENCES Member(memberID)
);
添加会员信息:
INSERT INTO Member (memberID, name, contact, type, fee) VALUES (1, '张三', '13812345678', 'VIP', 100.00);
修改会员信息:
UPDATE Member SET fee=150.00 WHERE memberID=1;
删除会员信息:
DELETE FROM Member WHERE memberID=1;
添加书籍信息:
INSERT INTO Book (bookID, title, author, publisher, category, quantity, price) VALUES (1, '红楼梦', '曹雪芹', '人民文学出版社', '古典小说', 5, 50.00);
修改书籍信息:
UPDATE Book SET price=60.00 WHERE bookID=1;
删除书籍信息:
DELETE FROM Book WHERE bookID=1;
查询书籍:
SELECT * FROM Book;
借阅书籍:
INSERT INTO Borrow (borrowID, memberID, bookID, borrowDate, returnDate, dueDate, actualReturnDate, status) VALUES (1, 1, 1, '2021-01-01', NULL, '2021-01-15', NULL, '借出');
归还书籍:
UPDATE Borrow SET actualReturnDate='2021-01-10', status='已归还' WHERE borrowID=1;
查询借阅信息:
SELECT * FROM Borrow;
查询收入信息:
SELECT * FROM Income;
书籍检索:
SELECT * FROM Book WHERE title LIKE '%红楼梦%';
计算罚款:
SELECT DATEDIFF(actualReturnDate, dueDate) * 0.1 AS fine FROM Borrow WHERE actualReturnDate > dueDate;
阅读全文