图书管理系统的相关表的创建维护

-- 图书管理系统数据库

use lms;

-- 创建用户表
create table user(
    userID int primary key auto_increment comment '用户id',
    name varchar(10) unique not null comment '用户姓名',
    password varchar(10) not null comment '密码'
);

-- 创建管理员表
create table manager like user;
alter table manager change userID managerID int comment '管理员ID';
alter table manager modify managerID int auto_increment;

-- 创建图书信息表
create table book(
  bookID char(10) unique not null comment '图书编号',
  bookName varchar(20) not null comment '书名',
  author varchar(20) not null comment '作者姓名',
  press varchar(20) not null comment '出版社',
  inventory int not null comment '库存'
);

-- 创建借阅历史表
create table history(
  bookID char(10) unique not null comment '图书编号',
  bookName varchar(20) not null comment '书名',
  num int check ( num>0 ) comment '借阅数量',
  date date comment '借阅时间'
);



drop table history;


desc manager;
desc user;
desc book;


select * from manager;
select * from user;
select * from history;

select * from book;


-- 插入用户信息
insert into user (name, password)
values ('任正非','12345678');
insert into user (name, password)
values ('马云','12345678');
insert into user (name, password)
values ('马化腾','12345678');

insert into user (name, password)
values ('刘强东','12345678');


-- 插入管理员信息
insert into manager (name, password) values ('熊壮','985211');
insert into manager (name, password) values ('戴慧','985211');
insert into manager (name, password) values ('熊壮','985211');

select * from manager;

-- 插入图书信息
insert into book value ('','','','',0);
insert into book value ('20180418hn','新概念英语','俞敏洪','新东方教育出版社',50);
insert into book value ('20220410bj','奇妙算法之旅','洪崇英','北京邮电出版社',30);
insert into book value ('20211020zj','更高更妙的数学解题思想方法','蔡培','浙江大学出版社',10);



update book set bookName = '', author = '', press = '', inventory = 0 where bookID = '';
update book set inventory = 0 where bookid = '' or bookName = '';
update book set bookID = '20170928bj' where author = '曲一线';


desc book;
select * from book;
select * from book where bookID = '1233333333' or bookName = '';
select count(*) from book;


-- 删除图书
delete from book where bookID = '' or bookName = '';

-- 查询图书库存
select inventory from book where bookID = '' or bookName = '';

-- 向借阅历史表插入信息
insert into history values('','',0,'');
insert into history value ('{BookID}','{BookName}',0,'{DateTime.Now.ToShortDateString()}';

--
update book set inventory = (inventory+1) where bookName = '新概念英语';

--
update history set num = (num+{num}) where bookID = '{BookID}' or bookName = '{BookName}'



select * from book;
select * from history;

use lms;


-- 还书方法
-- 更新书库信息
update book set inventory = (inventory + Num) where bookID = '';
-- 更新借阅历史
update history set num = (num - Num) where bookID = '';
-- 清空借阅信息
delete from history where bookID = '';
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

快阁东西倚晚晴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值