一、 需求分析
本数据库,为医院药品管理系统,本系统可以完成的功能有医院药品的信息管
理,药品的入库信息管理,药品的出库信息管理,药品在库存中的信息管理。每一
种信息管理都可以进行信息的更新,查询,删除,修改功能,也可运用约束来限制
操作人员对信息管理表的修改。还可通过视图等来完成对信息的快速精确查询。
二、 功能设计
1. 系统流程图
开始
MProduct
MStorein
MTakeout
MProinstore
添加记录
删除记录
修改记录
查询记录
选择对哪个表
进行操作
通过视图,存储过程
等查询
退出
2. 数据字典
MProduct 表(药品信息表)
字段
类型
长度
是否为空
备注
否
否
主键
药品编号
药品名称
药品别名
参考价格
药品分类
药品规格
生产厂家
Int
Varchar
Varchar
Decimal
Char
Varchar
varchar
50
50
15,2
10
50
50
MStorein 表(药品入库信息管理表)
字段
类型
长度
是否为空
备注
入库编号
药品编号
药品单价
入库药品数量
Int
Int
Decimal
Int
15,2
否
主键
外键参照 MProduct
入库日期
char
10
MTakeout(药品出库信息管理表)
字段
出库编号
入库编号
药品编号
参考价格
出库药品数量
出库日期
类型
Int
Int
Int
Decimal
Int
char
MProinstore(药品库存信息管理表)
字段
药品存储编号
药品编号
药品单价
药品数量
类型
Int
Int
Decimal
int
长度
是否为空
备注
否
主键
外键参照 MStorein
外键参照 MProduct
15,2
10
长度
是否为空
备注
否
否
主键
外键参照 MProduct
15,2
三、 概念设计
1.E-R 图
药品编号
入库信息
入库
库存信息
进价
日期
数量
进价
数量
2.关系图
四、 逻辑设计
关系模型为:
MProduct(药品编号,药品名称,药品别名,参考价格,药品分类,药品规格,
生产厂家)
主码:药品编号
MStorein(入库编号,药品编号,药品单价,入库药品数量,入库日期)
主码:入库编号
外码:药品编号参照于MProduct药品编号
MTakeout(出库编号,入库编号,药品编号,参考价格,出库药品数量,出库日
期)
主码:出库编号
外码:入库编号参照于MStorein入库编号
药品编号参照于MProduct药品编号
MProinstore(药品存储编号,药品编号,药品单价,药品数量)
主码:药品存储编号
外码:药品编号参照于MProduct药品编号
五、 数据库对象
1. 创建数据库
create database Medicine
2. 创建数据表
create table MProduct
(药品编号
药品名称
int primary key ,
varchar(50) not null,
varchar(50),
decimal(15,2),
char(10),
varchar(50),
varchar(50)
药品别名
参考价格
药品分类
药品规格
生产厂家
)
go
create table MStorein
(入库编号
药品编号
药品单价
入库药品数量
int primary key,
int,
decimal(15,2),
int,
char(10),
入库日期
foreign key (药品编号) references mproduct(药品编号)
)
go
create table MTakeout
(出库编号
入库编号
药品编号
参考价格
出库药品数量
int primary key,
int,
int,
decimal(15,2),
int,
char(10),
出库日期
foreign key (药品编号) references mproduct(药品编号),
foreign key (入库编号) references mstorein(入库编号)
)
go
create table MProinstore
(药品存储编号
药品编号
int primary key ,
int not null,
药品单价
decimal(15,2),
int,
药品数量
foreign key (药品编号) references mproduct(药品编号),
)
Go
六、 操作语句
1.创建视图
create view medicineview
as
select MProduct.药品编号,MProduct.药品名称,MStorein.入库日
期,MStorein.药品单价,MProduct.参考价格,MProinstore.药品数量
from MProduct,MProinstore,MStorein
where MProduct.药品编号=MStorein.药品编号and MProduct.药品编号
=MProinstore.药品编号
go
create view medicineview1
as
select MProduct.药品编号,MProduct.药品名称,MTakeout.出库药品数
量,MTakeout.出库日期,MProinstore.药品数量
from MProduct,MProinstore,MTakeout
where MProduct.药品编号=MTakeout.药品编号and MProduct.药品编号
=MProinstore.药品编号
go
2.存储过程
create procedure medicinepro
as
select 药品名称,药品别名,参考价格,生产厂家
from MProduct
where 药品编号='2'
go
执行存储过程
exec medicinepro
create procedure medicinepro1
as
select mproduct.药品名称,mproduct.药品别名,mstorein.入库药品数
量,mtakeout.出库药品数量
from MProduct,mstorein,mtakeout
where MProduct.药品编号=MTakeout.药品编号and mtakeout.药品编号
=mstorein.药品编号and mproduct.药品编号='8'
go
执行存储过程
exec medicinepro1
3. 创建触发器
create trigger noupdate
on MTakeout
for update
as
begin
raiserror('不得对Takeout表进行更新!',16,10)
end
go
验证触发器
update MTakeout
set 参考价格=参考价格+20
where 药品编号=4
触发器 2
create trigger nodelete
on MProinstore
for delete
as
begin
raiserror('不得对MProinstore表进行删除!',16,10)
end
go
验证触发器
delete
from MProinstore
where 药品编号='8'
4. 查询语句
select MProduct.药品编号,MProduct.药品名称,MStorein.入库日
期,MStorein.药品单价,MProduct.参考价格,MProinstore.药品数量
from MProduct,MProinstore,MStorein
where MProduct.药品编号=MStorein.药品编号and MProduct.药品编号
=MProinstore.药品编号
5. 更新语句
update MStorein
set 入库药品数量=入库药品数量+30
where 药品编号=4
6. 插入语句
insert into MProduct(药品编号,药品名称,参考价格,药品分类)
values('10','复方甘草合剂','10','中成药')
验证插入
select *
from MProduct
7. 删除语句
delete
from MTakeout
where 出库编号='5'
验证
七、 总结
在本次课程设计中,我独立完成了医院药品管理系统,通过任务指导书,我有条
理地计划每一个实验步骤,从构思系统功能到完成 SQL 语句,系统慢慢成形。在课程
设计中,我对数据库的使用熟悉了很多,很多地方以为自己可以很轻松地完成,真正
做起来,才知道没有笔上写得那么熟练。还有很多的地方,自己原来都没有注意到,
比如说数据关系图,原本不觉得有什么作用,现在发现它的重要。在这次课程设计结
束时,我对数据库的设计不再陌生,不再是只会在纸上书写的表层能力。