1、每日农产品价格行情管理系统数据库课程设计题目: 每日农产品价格行情管理系统 专 业: 信息管理与信息系统 班 级: 一、 系统需求分析 随着科学技术的发展,社会进步,计算机和互联网技术的迅速发展,信息的传播速度成倍加快。怎样才能迅速准确地掌握市场的最新动态、良好的货源和收购商成为了产品的商家和生产商在商场上立于不败之地的重要保证。农产品这一块也不例外,及时地掌握农产品的每日价格行情成为了农户和农产品批发商的迫切需求。每日农产品价格行情系统就是建立在这样一个基础上,为农户和农产品批发商建立一个了解农产品市场最新动态以及供求信息的平台。系统的主要功能1. 录入、修改和查询农产品的供求信息(主要是以
2、各个产品的品种类别,产地来划分的产品供求信息)2. 录入、更新和查询农产品的价格行情信息(上涨或是下跌)3. 给用户赋予权限和信息维护。2、系统功能结构图功能结构图:三、数据库设计1.系统ER图2.关系模式设计关系模式:农户:(农户编号,农户名,地区,电话) 农产品:(产品编号,产品类别,产品名称,产地) 批发商:(批发商编号,批发商店名,地区,电话,联系人) 零售商:(零售商编号,零售商店名,地区,电话,联系人)供给表(供给编号,农户编号,产品编号,供给量,供给时间,供给价格)进货表(进货编号,产品编号,批发商编号,进货量,进货时间,进货价格)批发表(批发编号,产品编号,批发商编号,零售商编
3、号,批发量,批发时间,批发价格)四、数据字典1. 数据项数据结构:2.数据结构:3.数据存储五数据库实现1.数据库表定义每日农产品价格管理系统create database 每日农产品价格管理系统供应商表(Supplier)字段名字段类型长度主键字段值约束对应中文名SupIDvarchar10PNot null供应商编号SupNameVarchar25Not null供应商名称SupareaVarchar50Not null供应商地址SupStyleIntNot null供应商类型SupPhoneVarchar20Not null 联系方式SupPWVarchar16Not null 供应商密
4、码create table Supplier(SupID varchar(10) not null primary key,SupName varchar(25) not null,SupArea varchar(50) not null,SupStyle int not null,SupPhone varchar(20) not null,SupPW Varchar(16) not null,)农产品信息表(ProductInfo)字段名字段类型长度主键字段值约束对应中文名ProductIDvarchar10PNot null农产品编号ProductStyleVarchar10Not nul
5、l农产品类别ProductNameVarchar50Not null产品名称ProductOriginVarchar20Not null产地ProductPriceMoneyNot null 产品价格SupIDvarchar10Not null供应商编号DistIDvarchar10Not null销售商编号create table ProductInfo(ProductID varchar(10) not null primary key,ProductStyle varchar(10) not null,ProductName varchar(50) not null,ProductOri
6、gin varchar(20) not null,ProductPrice money not null,SupID varchar(10) not null foreign key references Supplier(SupID),DistID varchar(10) not null foreign key references Distributer(DistID),)用户表(UserInfo)字段名字段类型长度主键字段值约束对应中文名UserIDvarchar10PNot null用户编号UserNameVarchar25Not null用户名称UserPWVarchar16Not
7、 null用户密码UserStyleIntNot null用户类型UserPhoneVarchar20Not null 联系方式UserAreaVarchar50Not null 用户地址create table UserInfo(UserID varchar(10) not null primary key,UserName varchar(25) not null,UserPW varchar(16) not null,UserStyle int not null,UserPhone varchar(20) not null,UserArea varchar(50) not null,)销
8、售商表(Distributer)字段名字段类型长度主键字段值约束对应中文名DistIDvarchar10PNot null销售商编号DistNameVarchar25Not null销售商名称DistareaVarchar50Not null销售商地址DistStyleIntNot null销售商类型DistPhoneVarchar20Not null 联系方式DistPWVarchar16Not Null销售商密码create table Distributer(DistID varchar(10) not null primary key,DistName varchar(25) not
9、null,Distarea varchar(50) not null,DistStyle int not null,DistPhone varchar(20) not null,DistPW varchar(16) not null,)分类汇总表(C_Summery)字段名字段类型长度主键字段值约束对应中文名C_Novarchar10PNot null分类汇总编号ProductStyleVarchar10Not null商品类型ProductNameVarchar50Not null商品名称Higest_PriceMoneyNot null最高价Lowest_PriceMoneyNot nul
10、l最低价Bulk_PriceMoneyNot null 大宗价Ave_PriceMoneyNot null平均价ProductIDvarchar10Not null农产品编号create table C_Summery(C_No varchar(10) not null primary key,ProductStyle varchar(10) not null,ProductName varchar(50) not null,Higest_Price money not null,Lowest_Price money not null,Bulk_Price money not null,Ave
11、_Price money not null,ProductID varchar(10) not null foreign key references ProductInfo(ProductID),)2.数据库关系图3. 触发器的编写1、CREATE TRIGGER UserInfo_delete1 ON UserInfo for DeleteAS begin delete Distributer from Distributer dt,deleted d where dt.DistID=d.UserIDEND GO/*在用户表中删除用户的同时将销售商表中对应的信息删除掉*/2、CREATE
12、TRIGGER UserInfo_delete ON UserInfo for DeleteAS begin delete Supplier from Supplier sp,deleted d where sp.SupID=d.UserIDEndGo/*在用户表中删除用户的同时将供应商表中的对应的信息删除掉*/3、CREATE TRIGGER UserInfo_insert ON UserInfo for insertAS declare UserID varchar(10), UserName Varchar(25), UserPW Varchar(16), UserStyle Int,
13、UserPhone Varchar(20), UserArea Varchar(50) select UserID=UserID, UserName=UserName, UserPW=UserPW, UserStyle=UserStyle, UserPhone=UserPhone, UserArea=UserArea from inserted where UserStyle=001or UserStyle=002begin insert into Supplier(SupID,SupName,SupPW,SupPhone,SupStyle,SupArea) values(UserID,Use
14、rName,UserPW,UserPhone,UserStyle,UserArea)EndGo/*当在用户表中插入的信息中“用户类型”为“001”或“002”时,在供应商表中插入相同的信息*/4、CREATE TRIGGER UserInfo_insert1 ON UserInfo for insertAS declare UserID varchar(10), UserName Varchar(25), UserPW Varchar(16), UserStyle Int, UserPhone Varchar(20), UserArea Varchar(50) select UserID=Us
15、erID, UserName=UserName, UserPW=UserPW, UserStyle=UserStyle, UserPhone=UserPhone, UserArea=UserArea From inserted where UserStyle=003or UserStyle=004begin insert into Distributer(DistID,DistName,DistPW,DistPhone,DistStyle,DistArea) values(UserID,UserName,UserPW,UserPhone,UserStyle,UserArea)EndGo/*当在
16、用户表中插入的信息中“用户类型”为“003”或“004”时,在销售商表中插入相同的信息*/5、CREATE TRIGGER UserInfo_update ON UserInfofor UPDATEAS if Update(UserID) BEGIN Update Supplier set SupID=i.UserID from Supplier sp,deleted d,inserted i where sp.SupID=d.UserIDEndGo/*在用户表更新用户信息时将供应商表中相应的信息进行同步更新*/6、CREATE TRIGGER UserInfo_update1 ON User
17、Infofor UPDATEAS if Update(UserID) BEGIN Update Distributer set DistID=i.UserID from Distributer dt,deleted d,inserted i where dt.DistID=i.UserIDEND Go/*在用户表更新用户信息时将销售商表中相应的信息进行同步更新*/7、CREATE TRIGGER Product_delete ON ProductInfofor DeleteAS begin delete C_Summery from C_Summery cs,deleted d where c
18、s.ProductName=d.ProductNameEND Go/*在用户表删除农产品信息时将汇总表中相应的信息进行删除*/8、CREATE TRIGGER Product_update ON ProductInfofor updateAS begin update C_Summery set ProductName=i.ProductName from C_Summery cs,deleted d,inserted i where cs.ProductName=d.ProductNameEND Go/*在用户表更新农产品信息时将汇总表中相应的信息进行同步更新*/4. 存储过程概述:以下所有
19、的存储过程:插入:表示插入一条新记录(如果记录已经存在,则插入失败)。修改:表示修改一条记录(如果记录存在则修改,否则不能修改)删除:表示删除一条记录(如果记录存在则删除,否则不能删除在此,我没有考虑到级联关系,感觉删除这个过程用触发器做比较好,因此,删除应由触发器实现。)。查询:表示查询记录(根据查询条件,显示相应的查询结果)供应商表的存储过程:1 插入 (如果该记录号已经存在,则不能再插入)If exists(select name from sysobjects where name =add_Supplier)Drop procedure add_SupplierGOGOcreate
20、procedure add_SupplierSupID varchar(10),SupName varchar(25),Suparea varchar(50),SupStyle int,SupPhone varchar(20),SupPW varchar(16)AsBegin transactionInsert into Supplier values (SupID,SupName,Suparea,SupStyle,SupPhone,SupPW)If(error!=0)BeginRollback transactionEndElsebegin Commit transactionEnd测试执行
21、上述存储过程Use 每日农产品价格管理Exec add_Supplier SupID=5,SupName=2,Suparea=3,SupStyle=12,SupPhone=4 ,SupPW=1232修改(根据记录号进行修改,如果记录号不存在则不能修改。修改时,每个字段都不能为空,不然修改不了)If exists(select name from sysobjects where name =edit_Supplier)Drop procedure edit_Supplier ;GOCreate procedure edit_SupplierSupID varchar(10),SupName v
22、archar(25),Suparea varchar(50),SupStyle int,SupPhone varchar(20),SupPW varchar(16)AsBegin transactionUpdate Supplier set SupName=SupName, Suparea=Suparea, SupStyle=SupStyle, SupPhone =SupPhone,SupPW=SupPW where SupID=SupID ;If(error!=0)BeginRollback transactionEndElsebegin Commit transactionEnd调用修改存
23、储过程:use 每日农产品价格管理Exec edit_Supplier SupID=2,SupName=aa,Suparea=aa,SupStyle=10,SupPhone=123654,SupPW=1113.删除(我只是做了个简单的对单个表的记录进行删除)If exists(select name from sysobjects where name =del_Supplier)Drop procedure del_Supplier ;GOCreate procedure del_SupplierSupID varchar(10)AsBegin transactionDelete from
24、Supplier where SupID=SupID If(error!=0)BeginRollback transactionEndElsebegin Commit transactionEnd调用删除存储过程:use 每日农产品价格管理Exec del_Supplier SupID=44. 查询 (根据查询条件,显示结果。条件可以是多个字段的)If exists(select name from sysobjects where name =select_Supplier)Drop procedure select_Supplier goCreate procedure select_Su
25、pplierSupID varchar(10),SupName varchar(25),Suparea varchar(50),SupStyle int,SupPhone varchar(20),SupPW varchar(16)AsBeginDeclare where varchar(100)Declare sql varchar(150)SET where=ERROR=0If(SupID)set where=where+ and +SupID=+SupIDif(SupName)set where=where+ and +SupName=+SupNameif(Suparea)set wher
26、e=where+ and +Suparea=+Supareaif(SupStyle)set where=where+ and +SupStyle=+CONVERT(VARCHAR(10),SupStyle)if(SupPhone)set where=where+ and +SupPhone=+SupPhoneif(SupPW)set where=where+ and +SupPW=+SupPWset sql=Select * from Supplier where +wherePRINT +sqlENDbegin transactionexec (sql) If(error0)BeginRol
27、lback transactionEndElsebegin Commit transactionEnd调用查询存储过程:use 每日农产品价格管理Exec select_Supplier SupID=,SupName=,Suparea=,SupStyle=12, SupPhone=,SupPW=(表示具体值。也可以为空,表示该字段没有要求)农产品信息表的存储过程(ProductInfo)1插入(如果该记录号已经存在,则不能再插入)If exists(select name from sysobjects where name =add_ProductInfo)Drop procedure ad
28、d_ProductInfo ;GOCreate procedure add_ProductInfoProductID varchar(10),ProductStyle varchar(10),ProductName varchar(50),ProductOrigin varchar(20),ProductPrice Money,SupID varchar(10),DistID varchar(10)AsBegin transactionInsert into ProductInfo values (ProductID, ProductStyle, ProductName, ProductOrigin, ProductPrice,SupID,DistID)If(error!=0)BeginRollback transactionEndElsebegin Commit transactionEnd调用插入存储过程
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1