1、课程设计课程名称:数据库系统概论 设计题目: 商品信息管理系统设计与实现院系名称 信息科学与工程学院 班 级 交通运送1202班 姓名与学号: 指引教师 1课题简介随着当代科技高速发展,设备和管理当代化,在实际工作中如何提高工作效率成为一种很重要问题。而建立管理信息系统是一种较好解决办法。 通过半年学习,咱们对计算机方面知识有了很大提高,本着理论联系实际宗旨,通过学校提供这次软件技术实践机会,在指引教师协助下,历经两周时间,咱们自行设计一套商品信息管理系统,在下面各章中,我将以这套商品管理系统为例,谈谈其开发过程和所涉及到问题。2设计目 应用对数据库系统原理理论学习,通过上机实践方式将理论知识
2、与实践更好结合起来,巩固所学知识。 数据库应用 课程实践:实践和巩固在课堂教学中学习关于知识,纯熟掌握对于给定构造数据库创立、基本操作、程序系统建立和调试以及系统评价。 数据库原理 软件设计实践:实践和巩固在课堂教学中学习关于关系数据库原理关于知识和数据库系统建立办法,纯熟掌握对于给定实际问题,为了建立一种关系数据库商品信息管理系统,必要得通过系统调研、需求分析、概念设计、逻辑设计、物理设计、系统调试、维护以及系统评价普通过程,为毕业设计打下基本。3设计内容 运用基于E-R 模型数据库设计办法和关系规范化理论做指引完毕从系统分析到设计直至系统最后实现,开发商品信息系统,完毕商品信息管理系统所有
3、功能,商品入库子系统,商品出库子系统,商品库存子系统。 一方面做好需求分析,并完毕数据流图和数据字典。 另一方面做概念分析,运用实体联系办法将需求分析顾客需求抽象为信息构造,得到E-R 图。 然后就是逻辑构造设计,将E-R 图转换为计算机系统所支持逻辑模型4 设计详细实行一、 进行需求分析,编写数据字典。1、系统功能规定设计 有一种存储商品仓库,每天均有商品出库和入库。 每种商品均有商品编号、商品名称、生产厂家、型号、规格等。 入库时必要填写入库单据,单据涉及商品名称、生产厂家、型号、规格、入库数量、入库日期、入库仓库号、入库仓库名称、送货人姓名。 出库时必要填写出库单据,单据涉及仓库号、仓库
4、名称、商品编号、商品名称、型号、规格、出库数量、出库日期、提货人姓名。 设立商品库存台帐,商品库存台帐是对仓库中当前库存所有商品明细记录,商品库存台帐涉及商品编号、商品名称、型号、规格、库存数量、库存日期。每当有商品入库或商品出库时都应当自动修改该台帐,最后一次修改是当前库存状况。 商品入库和出库过程通过库存台帐更加清晰条理地显示出仓库中商品库存数量和库存日期等信息,容易对库存内商品信息进行查询,增长,修改,删除等操作。 该仓库商品型号统一为DA01-DA99格式,规格为CX100-CX199格式重要功能: 商品管理: 增长商品:修改商品,删除商品,浏览商品增长商品:实现增长商品详细资料功能修
5、改商品:实现修改商品资料功能删除商品:实现删除该商品所有资料功能浏览商品:实现浏览所有商品功能 库存管理: 实现商品入库,在商品入库时通过触发器或存储过程同步完毕商品库存台帐更新。实现商品出库,在商品出库时通过触发器或存储过程同步完毕商品库存台帐更新。实现按商品名称查询商品入库状况及当前库存量。实现按入库日期查询商品入库状况及当前库存量。实现按商品名称查询商品出库状况及当前库存量。实现按出库日期查询商品出库状况及当前库存量。准时间段查询商品库存状况。实现分别按年、季度和月对入库商品数量记录。实现分别按年、季度和月对出库商品数量记录。2、系统模块设计库存物资管理大体可以分为如下3大模块,如下图所
6、示:一方面是商品入库模块,该模块重要就是描述把采购回来商品,分类别放置到指定仓库中去,然后是商品出库模块,该模块重要描述从指定仓库中拿出商品;最后时库存模块,这个模块重要是记录商品库存数量变化。商品信息管理商 品 入 库 模 块商 品 出 库 模 块商 品 库 存 模 块3、数据字典表表名中文名Ware商品Depot仓库Stock库存Stocking入库Outbound出库商品Ware字段名数据类型与否可觉得空Is PKIs FK中文名WNochar(10)NOT NULLYesNo商品编号WNamevarchar(50)NOT NULLNoNo商品名称WFactoryvarchar(50)N
7、OT NULLNoNo生产厂家WTypevarchar(20)NOT NULLNoNo型号Specvarchar(20)NOT NULLNoNo规格仓库 Depot字段名数据类型与否可觉得空Is PKIs FK中文名DNochar(10)NOT NULLYesNo仓库号DNamevarchar(50)NOT NULLNoNo仓库名称库存Stock字段名数据类型与否可觉得空Is PKIs FK中文名WNochar(10)NOT NULLYesYes商品编号Dnochar(10)NOT NULLYesYes仓库号WAmountIntNOT NULLNoNo库存数量入库Stocking字段名数据类型
8、与否可觉得空Is PKIs FK中文名SNochar(10)NOT NULLYesNo入库号WNochar(10)NOT NULLNoYes商品编号Dnochar(10)NOT NULLNoYes仓库号SAmountIntNOT NULLNoNo入库数量SDatesmalldatetimeNOT NULLNoNo入库日期Suppliervarchar(50)NOT NULLNoNo送货人姓名出库Outbound字段名数据类型与否可觉得空Is PKIs FK中文名ONochar(10)NOT NULLYesNo出库号WNochar(10)NOT NULLNoYes商品编号Dnochar(10)N
9、OT NULLNoYes仓库号OAmountintNOT NULLNoNo出库数量ODatesmalldatetimeNOT NULLNoNo出库日期Buyersvarchar(50)NOT NULLNoNo提货人姓名二、 设计完整E-R图。商品编号型号生产厂家规格商品名称商品仓库号仓库仓库名称商品仓库库存nm商品仓库入库nm商品仓库出库nm库存关系:入库关系:出库关系:分E-R图:总E-R图:商品编号型号生产厂家规格商品名称商品仓库号仓库仓库名称入库日期送货人姓名入库数量入库入库号nnnmmm库存库存数量提货人姓名出库日期出库数量出库出库号三、 进行数据库逻辑设计。关系模式如下:商品(商品编
10、号、商品名称、生产厂家、型号、规格) 商品编号为主键仓库(仓库号、仓库名称) 仓库号为主键库存(商品编号,仓库号,库存数量) (商品编号,仓库号)为主键,同步也分别为外键入库(入库号,商品编号,仓库号,入库数量,入库日期,送货人姓名)(入库号)为主键,(商品编号,仓库号)为外键出库(出库号,商品编号,仓库号,出库数量,出库日期,提货人姓名)(出库号)为主键,(商品编号,仓库号)为外键四、 完毕物理数据库设计,(涉及数据库、表、索引、视图、完整性约束物理设计。)创立数据库create database Material_DB创立商品表use Material_DBcreate table War
11、e( /*定义商品表*/WNo char(10) NOT NULL primary key,WName varchar(50) NOT NULL,WFactory varchar(50) NOT NULL,WType varchar(20) NOT NULL,Spec varchar(20) NOT NULL)use Material_DB /*插入商品信息*/insert into Warevalues (100000,毛巾,新家园,DA11,CX100);insert into Warevalues (100001,台灯,新家园,DA35,CX110);insert into Wareva
12、lues (100002,电冰箱,海尔,DA61,CX900);insert into Warevalues (100003,电视,东芝,DA52,CX901);insert into Warevalues (100004,长城干红,中粮华夏,DA25,CX108);insert into Warevalues (100005,笔记本,东芝,DA24,CX781);创立仓库表use Material_DBcreate table Depot( /*定义仓库表*/DNo char(10) NOT NULL primary key,DName varchar(50) NOT NULL)use Ma
13、terial_DB /*插入仓库信息*/insert into Depotvalues (001,胜昌);insert into Depotvalues (002,德隆);insert into Depotvalues (003,豪友);创立库存表use Material_DBcreate table Stock ( /*定义库存关系*/WNo char(10) NOT NULL,DNo char(10) NOT NULL,-WDate smalldatetime NOT NULL,WAmount int NOT NULL,primary key(WNo,Dno),foreign key (W
14、No) references Ware(WNo),foreign key (DNo) references Depot(DNo)创立入库表use Material_DBcreate table Stocking( /*定义入库关系*/SNo char(10) NOT NULL primary key,WNo char(10) NOT NULL,DNo char(10) NOT NULL,foreign key (WNo) references Ware(WNo),foreign key (DNo) references Depot(DNo),SAmount Int NOT NULL,SDate
15、 smalldatetime NOT NULL,Supplier varchar(50) NOT NULL)创立出库表use Material_DBcreate table Outbound( /*定义出库关系*/ONo char(10)NOT NULL primary key,WNo char(10)NOT NULL ,foreign key (WNo)references Ware(WNo),DNo char(10) NOT NULL,foreign key (DNo) references Depot(DNo),OAmount int NOT NULl ,ODate smalldatet
16、ime NOT NULL,Buyers varchar(50) NOT NULL)完整约束阐明:商品WareWNo商品编号规定在100000999999之间,WName不能取空;仓库DepotDNo仓库编号规定在001999之间,DName不能取空;该仓库商品型号统一为DA01-DA99格式,规格为CX100-CX199格式。use Material_DB /*定义表Ware唯一性约束条件*/alter Table Ware add unique(WName,WFactory,WType,Spec);alter Table Ware /*定义WType完整性约束条件:商品型号统一为DA01-D
17、A99格式*/add constraint C2 check(WType like DA0-91-9);alter Table Ware /*定义Spec完整性约束条件:规格为CX100-CX199格式*/add constraint C3 check(Spec like CX1-90-90-9);use Material_DBalter table Ware /*添加对表WareWNo属性完整性约束,规定在之间*/add constraint C4 check(WNo like1-90-90-90-90-90-90-90-90-90-9);alter table Depotadd const
18、raint C5 check(DNo like20100-90-90-9);use Material_DBalter table Waredrop constraint C4;use Material_DBalter table Ware /*添加对表WareWNo属性完整性约束,规定在999999之间*/add constraint C4 check(WNo like1-90-90-90-90-90-9);创立视图通过WLST(提取“物料视图”每个字头字母)视图来浏览库存中相似编号商品信息,其中涉及:商品编号WNo、商品名WName、商品厂家WFactory、商品型号WType、商品规格Sp
19、ec、商品数量SNum、create view VWname(商品编号,商品名称,库存数量)-视图ASSELECT Stock.WNo,Ware.WName,sum(Stock.WAmount)from Ware,Stockwhere Stock.WNo=Ware.WNo group by Stock.WNo,Ware.WName;五、 实现商品入库,在商品入库时通过触发器或存储过程同步完毕商品库存台帐更新。入库表触发器create trigger stocking_into on stocking -这是入库表触发器 after insert asbegin declare a char(1
20、0),b char(10),d int;select a=i.DNo,b=i.WNo,d=i.SAmountfrom inserted as i;if(select Stock.WNo from Stock where Stock.WNo=b and Stock.DNo=a) is not nullbeginupdate Stockset Stock.WAmount=Stock.WAmount+dwhere Stock.WNo=b and Stock.DNo=a;return;endinsert into stock values(b,a,d);endinsert into stocking
21、values(100,100005,001,200,-01-02,小明);insert into stocking values(101,100005,003,200,-01-02,小兰);insert into stocking values(102,100001,003,200,-01-02,小东);insert into stocking values(103,100002,001,200,-01-02,小红);insert into stocking values(104,100003,001,200,-01-14,小风);insert into stocking values(105
22、,100005,002,200,-01-25,小明);insert into stocking values(106,100000,002,200,-02-02,小明);insert into stocking values(107,100001,001,200,-03-02,小东);insert into stocking values(108,100002,002,200,-04-02,小红);insert into stocking values(109,100003,003,200,-04-02,小风);insert into stocking values(110,100004,00
23、1,200,-06-09,小敏);insert into stocking values(111,100004,002,200,-06-02,小风);insert into stocking values(112,100005,001,200,-06-02,小青);insert into stocking values(113,100000,003,200,-06-02,小明);insert into stocking values(114,100001,001,200,-06-02,小东);insert into stocking values(115,100002,002,200,-07-
24、02,小红);insert into stocking values(116,100003,003,200,-08-02,小风);insert into stocking values(117,100000,001,200,-08-02,小明);insert into stocking values(118,100001,001,200,-09-04,小东);insert into stocking values(119,100002,002,200,-06-02,小红);insert into stocking values(120,100003,003,200,-09-11,小风);ins
25、ert into stocking values(121,100002,002,200,-09-01,小明);insert into stocking values(122,100003,002,200,-07-08,小敏);insert into stocking values(123,100002,003,200,-04-11,小敏);insert into stocking values(124,100001,001,200,-07-08,小红);insert into stocking values(125,100001,003,200,-08-21,小青);insert into s
26、tocking values(126,100005,001,200,-07-08,小青);insert into stocking values(127,100003,003,200,-09-01,小兰);insert into stocking values(128,100002,002,200,-07-08,小兰);insert into stocking values(129,100004,001,200,-07-08,小兰);insert into stocking values(130,100005,002,200,-07-08,小红);六、 实现商品出库,在商品出库时通过触发器或存
27、储过程同步完毕商品库存台帐更新。出库表触发器create trigger outbound_d on Outbound -这是出库表触发器 after insert as begin declare a char(10),b char(10),d int ; select a=i.DNo,b=i.WNo,d=i.OAmount from inserted as iif(select s.WNo from Stock as s where s.DNo=a and s.WNo=b ) is not nullbeginif(select s.WAmount from Stock as s ,inse
28、rted where s.WAmount=inserted.OAmount and s.WNo=inserted.WNo and s.DNo=inserted.DNo) is not nullbeginupdate Stock set Stock.WAmount=Stock.WAmount-dwhere Stock.DNo=a and Stock.WNo=bendelsebeginprint 库存量不够rollbackendendelsebeginprint 库存中没有这种产品rollbackendendinsert into Outbound values(1,100005,001,50,-
29、01-02,小红);insert into Outbound values(2,100005,002,30,-01-02,小红);insert into Outbound values(3,100001,003,50,-01-02,小风);insert into Outbound values(4,100005,001,30,-01-02,小红);insert into Outbound values(5,100002,002,20,-02-08,小风);insert into Outbound values(6,100003,003,50,-03-09,小红);insert into Out
30、bound values(7,100000,002,30,-04-15,小风);insert into Outbound values(8,100004,002,50,-04-15,小风);insert into Outbound values(9,100005,001,30,-06-02,小红);insert into Outbound values(10,100005,002,50,-04-15,小红);insert into Outbound values(11,100001,003,50,-06-03,小风);insert into Outbound values(12,100005,
31、001,30,-04-15,小红);insert into Outbound values(13,100002,002,20,-07-05,小风);insert into Outbound values(14,100003,003,50,-07-05,小红);insert into Outbound values(15,100000,002,40,-07-05,小风);insert into Outbound values(16,100004,002,50,-07-05,小风);insert into Outbound values(17,100005,002,20,-09-01,小明);in
32、sert into Outbound values(18,100001,003,30,-09-01,小敏);insert into Outbound values(19,100000,002,40,-09-01,小敏);insert into Outbound values(20,100002,002,50,-09-01,小红);insert into Outbound values(21,100000,002,20,-08-21,小青);insert into Outbound values(22,100003,001,30,-09-01,小青);insert into Outbound v
33、alues(23,100002,002,40,-09-01,小兰);insert into Outbound values(24,100003,003,50,-12-30,小兰);insert into Outbound values(25,100004,002,20,-12-30,小兰);insert into Outbound values(26,100005,001,40,-12-08,小红);insert into Outbound values(27,100001,003,10,-12-30,小敏);insert into Outbound values(28,100002,002,
34、30,-12-08,小明);insert into Outbound values(29,100003,003,30,-12-18,小红);insert into Outbound values(30,100004,001,40,-09-01,小敏);七、 实现按商品名称查询商品入库状况及当前库存量。/*办法一*/select SNo,WName,s.WNo,s.DNo,SAmount,WAmount from Stock as s,Ware as w,Stocking as siwhere WName=电冰箱 and s.WNo=w.WNo and w.WNo=si.WNo and s.DN
35、o=si.DNo/*办法二*/ declare WName varchar(32)SET WName =电冰箱SELECT * FROM Stocking WHERE WNo IN (SELECT WNo FROM Ware WHERE WName = WName);/*办法三*/CREATE VIEW LSName(SNo,WName,WNo,DNo,SAmount,WAmount)ASselect SNo,WName,s.WNo,s.DNo,SAmount,WAmountfrom Stock as s,Ware as w,Stocking as si select distinct si.
36、Sno,l.WName,si.SAmount,s.WAmountFROM Stock as s,LSName as l,Ware as w,Stocking as siWHERE l.WName=电冰箱 and si.Sno=l.Sno and w.WName=l.WName and s.WNo=si.WNo and si.WNo=w.WNo and w.WNo=l.WNo and si.DNo=l.DNo and si.SAmount=l.SAmount and s.WAmount=l.WAmount 八、 实现按入库日期查询商品入库状况及当前库存量。/*办法一 复合条件查询*/select
37、 SNo,s.WNo,s.DNo,SAmount,SDate,Supplier,WAmount from Stock as s,Stockingwhere SDate=-01-02 00:00:00 and s.WNo=Stocking.WNo and s.DNo=Stocking.DNo/*办法二建立视图查询*/create view WA_Stocking(SNo,WNo,DNo,SAmount,SDate,Supplier,WAmount)as select SNo,s.WNo,s.DNo,SAmount,SDate,Supplier,WAmount from Stock as s JO
38、IN Stocking on s.WNo=Stocking.WNo and s.DNo=Stocking.DNo and SDate=-01-02 00:00:00with check option;/*办法三有关子查询*/select SNo,s.WNo,s.DNo,SAmount,SDate,Supplier,WAmount from Stock as s,Stockingwhere exists (select * where SDate=-01-02 00:00:00 and s.WNo=Stocking.WNo and s.DNo=Stocking.DNo);九、 实现按商品名称查询
39、商品出库状况及当前库存量。/*办法一*/select ONo,s.WNo,s.DNo,OAmount,WName,ODate,Buyers,WAmount from Stock as s,Outbound,Warewhere WName=长城干红 and Ware.Wno=s.Wno and s.Wno=Outbound.Wno and s.DNo=Outbound.DNo/*办法二*/* 创立视图*/CREATE VIEW W_S_O(ONo,WNo,DNo,OAmount,ODate,Buyers,WAmount,WName)ASSELECT ONo,Stock.WNo,Stock.DNo
40、,OAmount,ODate,Buyers,WAmount,Ware.WNameFROM Ware,Stock,OutboundWHERE Stock.WNo=Outbound.WNo AND Stock.DNo=Outbound.DNo AND Ware.WNo=Stock.Wnoselect ONo,WNo,DNo,OAmount,WName,ODate,Buyers,WAmount from W_S_Owhere WName=长城干红 /*办法三*/declare WName varchar(32)set WName=长城干红select *from Outbound where WNo
41、=(select WNo from Ware where WName=WName);/*办法四*/select ONo,s.WNo,s.DNo,OAmount,WName,ODate,Buyers,WAmount from Stock as s,Outbound,Warewhere exists (select *where WName=长城干红 and s.WNo=Outbound.WNo and s.DNo=Outbound.DNo and Ware.Wno=s.Wno);十、 实现按出库日期查询商品出库状况及当前库存量。/*办法一*/ select ONo,s.WNo,s.DNo,OAm
42、ount,ODate,Buyers,WAmount from Stock as s,Outboundwhere ODate=-01-02 0:00:00 and s.WNo=Outbound.WNo and s.DNo=Outbound.DNo/*办法二*/* 创立视图*/CREATE VIEW SO(ONo,WNo,DNo,OAmount,ODate,Buyers,WAmount)ASSELECT ONo,Stock.WNo,Stock.DNo,OAmount,ODate,Buyers,WAmountFROM Stock,OutboundWHERE Stock.WNo=Outbound.WNo AND Stock.DNo=Outbound.D