当前位置:文档之家› 供应链管理系统的数据库设计

供应链管理系统的数据库设计

供应链管理系统的数据库设计1.系统需求分析a.通过建立供应链的数据库建立以方便各种信息的查询与管理工作。

b.系统简述:本系统包括六个实体:生产商;运输商;商场;仓库;商品;顾客包括四个关系转为四个表:运输;生产;销售;储存。

c.对该数据库进行如下数据处理:Ⅰ查询:①查询其商场所有的信息,输入商场编号,输出信息②查询某种商品的生产、运输、商场的信息,输入商品的编号,输出生产商、运输时间、运输商、销售商场③商场想查询某一类的商品储存仓库信息,输入商品编号,输出仓库编号地址、储存时间④查询商品列表里的各类商品个数,并按类型分组。

Ⅱ.插入:①在商品表中插入新商品②插入新的销售记录③插入新的运输记录Ⅲ.修改:①修改旧商品的价格②修改运输的记录二.系统概念模型(E-R图)①实体的关系图:②实体的属性图:③关系属性图:三、关系模式(加下划线的是主键)①生产商关系:(生产商编号,生产商名称,生产商地址,生产商类型,生产商注册年份)②运输商关系:(运输商编号,运输商名称,运输商注册年份,运输商地址,运输商车辆数)③商场关系:(商场编号, 商场名称, 商场注册年份, 商场地址, 商场规模)④顾客关系:(顾客身份证号, 顾客姓名, 顾客年龄,顾客性别)⑤仓库关系:(仓库编号, 仓库地址, 仓库存储价格)⑥商品关系:(商品编号, 商品名称, 商品价格, 商品类型)⑦生产关系:(生产编号, 商品编号,生产商编号, 生产时间)⑧运输关系:(运输编号, 商场编号, 生产商编号, 商品编号, 运输时间, 运输商编号)⑨销售关系:(顾客身份证号, 商场编号, 商品编号, 销售编号, 销售时间)⑩储存关系:(储存编号, 商品编号, 仓库编号, 储存时间,所属商场)四、物理设计①生产商:②运输商:③商场:④顾客:⑥商品:⑦生产:⑧运输:⑨销售:⑩储存:五、系统实现1.数据库及其基本表的建立数据库的建立用企业管理器,基本表用T-SQL语言:数据库名:PM-System建立数据库的T-SQL语句如下:Create database PM-SystemOn(name=pm_system_data,filename=’E:\数据库 \’)Log on(name=pm_system_log,filename=’E:\ 数据库\’)建立表的SQL语句如下:Use PM_SystemCreate table 生产商(生产商编号 char(20) primary key,生产商名称 char(20) not null,生产商地址 char(20) not null,生产商类型 char(20),生产商注册年份 datetime not null)Create table 运输商(运输商编号char(20)primary key,运输商名称char(10)not null,运输商注册年份 datetime not null,运输商地址 char(20) not null,运输商车辆数 int not null)Create table 商场(商场编号char(20) primary key,商场名称char(10)not null,商场地址char(20)not null,商场注册年份datetime not null,Create table 顾客(顾客身份证号char(20) primary key,顾客姓名char(10) not null,顾客年龄 int,顾客性别char(2) not null)Create table 仓库(仓库编号 char(20) primary key,仓库地址char(10)not null,仓库存储价格money not null)Create table 商品(商品编号char(20)primary key,商品名称char(10)not null,商品价格money not null,商品类型char(20)not null)Create table 生产(生产编号char(20) primary key,商品编号char(20)not null,生产商编号char(20) not null references 生产商(生产商编号),生产时间datetime not null)Create table 运输(运输编号char(20)primary key,生产商编号char(20)not null,商品编号 char(20)not null,运输时间datetime,运输商编号char(20) not null references 运输商(运输商编号) )Create table 销售(顾客身份证号char(20)not null,商场编号char(20)not null,商品编号char(20)not null references 商品(商品编号),销售编号Char(10)primary key,销售时间char(20)not null)Create table 存储( 储存编号 char(20) pimary key,商品编号 Char(20) not null,仓库编号 char(20) not null references 仓库(仓库编号),储存时间 char(20) not null,所属商场char(20)not null)输入数据:Insert into 生产商values(‘0001’,’可口可乐’,’北京’,’食品’,’2010.01.01’)Insert into 生产商values(‘0002’,’百事可乐’,’天津’,’食品’,’2010.01.02’)Insert into 生产商values(‘0003’,’ADIDAS运动鞋’,’北京’,’鞋帽’,’2010.02.01’)Insert into 生产商values(‘0004’,’Audi A4’,’北京’,’汽车’,’2010.03.01’)Insert into 生产商values(‘0005’,’麦当劳’,’北京’,’食品’,’2010.04.01’)Insert into 运输values(‘0001’,’运一’,’2009.09.01’,’北京’,’10’)Insert into运输values(‘0002’,’运二’,’2010.01.01’,’北京’,’20’)Insert into运输values(‘0003’,’运三’,’2010.02.02’,’天津’,’30’)Insert into运输values(‘0004’,’运四’,’2009.09.01’,’天津’,’40’)Insert into运输values(‘0005’,’运五’,’1997.01.02’,’上海’,’20’)Insert into 商场values(‘0001’,’商场一’,’天津’’2009.01.01’,’大’)Insert into商场values(‘0002’,’商场二’,’北京’’2010.01.01’,’小’)Insert into商场values(‘0003’,’商场三’,’上海’’2010.02.02’,’小’)Insert into商场values(‘0004’,’商场四’,’长沙’’2010.03.01’,’大’)Insert into 仓库values(‘0001’,’上海’’1000’)Insert into仓库values(‘0002’,’天津’,’500’)Insert into仓库values(‘0003’,’天津’,’1000’)Insert into仓库values(‘0004’,’北京’,’2000’)Insert into 商品values(‘0001’,’百事可乐’,’5’,’食品’)Insert into商品values(‘0002’,’美年达’,’4’,’食品’)Insert into商品v alues(‘0003’,’可口可乐’,’4’,’食品’)Insert into商品values(‘0004’,’汉堡’,’10’,’食品’)Insert into商品values(‘0005’,’Audi A5’,’300000’,’汽车’)Insert into商品values(‘0001’,’Audi A6’,’400000’,’汽车’)Insert into商品values(‘0002’,’Audi A4’,’200000’,’汽车’)Insert into商品values(‘0003’,’ADIDAS运动鞋1’,’300’,’鞋帽’)Insert into商品values(‘0004’,’ADIDAS运动鞋2’,’400’,’鞋帽’)Insert into商品values(‘0005’,’ADIDAS运动鞋3’,’500’,’鞋帽’)Insert into 顾客values(‘3009201001’,’赵一’,’20’,’女’)Insert into 顾客values(‘3009202001’,’钱二’,’19’,’男’)Insert into 顾客values(‘3009203001’,’李三’,’21’,’女’)Insert into 顾客values(‘3009204001’,’王五’,’22’,’男’)Insert into 生产values(‘0001’,’0001’,’0002’,’2009.09.05’)Insert into 生产values(‘0002’,’0003’,’0002’,’2009.09.01’)Insert into 生产values(‘0003’,’0003’,’0001’,’,03’)Insert into 生产value s(‘0004’,’0004’,’0005’,’2010.07.04’)Insert into生产values(‘0005’,’0005’,’0004’,’,05’)Insert into生产values(‘0006’,’0006’,’0004’,’2010.07.06’)Insert into生产values(‘0007’,’0007’,’0003’,’2010.07.07’)Insert into生产values(‘0008’,’0008’,’0003’,’2010.07.08’)values(‘0009’,’0009’,’0003’,’2010.07.09’)Insert into生产values(‘0010’,’0010’,’0003’,’2010.07.10’)Insert into 运输values(‘1’,’0001’,’0002’,’0001’,’2009.09.05’,’0001’)Insert into 运输values(‘2’,’0004’,’0002’,’0002’,’2009.09.01’,’0002’)Insert into运输va lues(‘3’,’0003’,’0001’,’0004’,’,03’,’0004’)Insert into运输values(‘4’,’0003’,’0005’,’0003’,’2010.07.04’,’0005’)Insert into运输values(‘5’,’0005’,’0004’,’0003’,’,05’,’0002’)Insert into运输values(‘6’,’0006’,’0004’,’0002’,’2010.07.06’,’0005’)Insert into运输values(‘7’,’0003’,’0003’,’0001’,’2010.07.07’,’0003’)Insert into运输values(‘8’,’0002’,’0003’,’0002’,’2010.07.08’,’0002’)Insert into运输values(‘9’,’0006’,’0003’,’0001’,’2010.07.09’,’0001’)Insert into运输values(‘10’,’0005’,’0003’,’0002’,’2010.07.10’,’0001’)Insert into 销售values(‘20021’,’0001’,’0001’,’0001’,’2010.01.01’)values(‘30001’,’0001’,’0002’,’20’,’女’)Insert into 销售values(‘90008’,’0001’,’0003’,’20’,’女’)Insert into 销售values(‘20058’,’0003’,’0004’,’20’,’女’)Insert into 销售values(‘30011’,’0002’,’0005’,’20’,’女’)Insert into 销售values(‘22021’,’0002’,’0006’,’20’,’女’)Insert into 销售values(‘20021’,’0004’,’0007’,’20’,’女’)Insert into 储存values(‘0001’,’0003’,’0001’,’2010.11.01’ ,’0001’)Insert into 储存values(‘0002’,’0002’,’0001’,’2010.11.05’,’0003’)Insert into 储存values(‘0003’,’0001’,’0002’,’2010.11.10’,’0004’)2.创建索引create nonclusteredindex idx生产商on生产商(生产商编号)create nonclusteredindex idx运输on运输(生产商编号)create nonclusteredindex idx运输2on运输(商场编号)create nonclusteredindex idx商场on商场(商场编号)create nonclusteredindex idx储存on储存(仓库编号)create nonclusteredindex idx仓库on仓库(仓库编号)3.创建视图create view 供应链图asselect 生产商名称,运输商名称,商场名称,商品.商品编号,运输时间, 商品类型, 生产时间from 生产商 join 运输 on 生产商.生产商编号=运输.生产商编号join 运输商 on 运输商.运输商编号=运输.运输商编号 join 商场 on 商场.商场编号=运输.商场编号join 商品 on 商品.商品编号=运输.商品编号 join 生产 on 生产. 商品编号=商品.商品编号create view 存储图asselect 仓库.仓库编号,商品编号,所属商场from 商场 join 存储 on 商场.商场编号=存储.所属商场 join 仓库on 仓库.仓库编号=存储.仓库编号4.创建存储过程①查询:create procedure 商场信息 @shopID char(10)asbeginprint 'list of the information of this shop'select 商场名称,商场地址,商场规模,商场注册年份from 商场where 商场编号=@shopIDendcreate procedure 供应链信息 @goodID char(20)asbeginprint 'list of the information of this good’s provide' select 生产商名称,运输商名称,商场名称from 供应链图where 商品编号=@goodIDendcreate procedure 储存信息 @goodID char(20)asbeginprint 'list of the storage'select 仓库编号,商品编号,所属商场from 存储图where 商品编号=@goodIDendcreate procedure 分类信息 @goodID char(20)asbeginselect 商品类型,count(*)from 商品group by 商品类型end②插入:create procedure 插入商品信息 @goodID char(20), @goodname char(10), @goodprice money , @goodtype char(20)asinsert into 商品values(@goodID, @goodname, @goodprice, @goodtype)create procedure 插入销售记录 @personid char(20),@shopnameID char(20), @goodid char(20), @sellID char(20),@selltime datetimeasinsert into 销售values(@personid, @shopnameID, @goodid, @sellID, @selltime)③修改Create procedure 修改商品价格 @goodprice money,@goodid char(20)AsUpdate 商品Set 商品价格=@goodpriceWhere 商品编号=@goodidCreate procedure 修改运输记录 @oldtid char(20),@tidchar(20),@shopid char(20),@tpid char(20),@goodidchar(20),@time datetime,@fid char(20)As update 运输Set 运输编号=@tid,运输商编号=@tpid,生产商编号=@fid,商品编号=@goodid,运输时间=@time,商品编号=@shopidWhere 运输编号=@oldtid21。

相关主题