辽 宁 工 业 大 学 课 程 设 计 说 明 书(论 文)
仓库编号 varchar(30) not null, 入库单价 money not null, 入库数量 int not null constraint CKC_入库数量_入库明细check (入库数量>= 1), 供应商名 varchar(40) not null,
constraint PK_入库明细primary key nonclustered (入库编号, 入库明细行号) ) go
create index Relationship_1_FK on 入库明细( 入库编号ASC ) go
create index Relationship_2_FK on 入库明细( 商品编号ASC ) go
create index Relationship_3_FK on 入库明细( 仓库编号ASC ) go
create table 出库单(
出库编号 varchar(30) not null, 出库时间 datetime not null, 出库经办人 varchar(20) not null, 备注 text null,
constraint PK_出库单primary key nonclustered (出库编号) ) go
create table 出库明细(
出库编号 varchar(30) not null, 出库明细行号 varchar(30) not null, 仓库编号 varchar(30) not null, 商品编号 varchar(30) not null, 出库单价 money not null, 出库数量 int not null constraint CKC_出库数量_出库明细check (出库数量>= 1), 客户名称 varchar(40) not null,
constraint PK_出库明细primary key nonclustered (出库编号,) go
create index Relationship_5_FK on 出库明细( 商品编号ASC ) go
8
) 出库明细行号辽 宁 工 业 大 学 课 程 设 计 说 明 书(论 文)
create index Relationship_4_FK on 出库明细( 出库编号ASC ) go
create index Relationship_9_FK on 出库明细( 仓库编号ASC ) go
create table 商品信息(
商品编号 varchar(30) not null, 商品名称 varchar(50) not null, 商品类别 varchar(20) not null, 商品规格 varchar(20) null, 计量单位 varchar(20) not null, constraint PK_商品信息primary key nonclustered (商品编号) ) go
create table 库存(
仓库编号 varchar(30) not null, 商品编号 varchar(30) not null, 库存数量 int not null, 库存下限 int not null, 库存上限 int not null, constraint PK_库存primary key (仓库编号, 商品编号) ) go
create index 库存_FK on 库存( 仓库编号ASC ) go
create index 库存_FK on 库存( 商品编号ASC ) go
alter table 借条信息
add constraint FK_借条信息_RELATIONS_商品信息foreign key (商品编号) references 商品信息(商品编号) go
alter table 借条信息
add constraint FK_借条信息_RELATIONS_仓库foreign key (仓库编号) references 仓库(仓库编号) go
9
辽 宁 工 业 大 学 课 程 设 计 说 明 书(论 文)
alter table 入库明细
add constraint FK_入库明细_RELATIONS_入库单foreign key (入库编号) references 入库单(入库编号) go
alter table 入库明细
add constraint FK_入库明细_RELATIONS_商品信息foreign key (商品编号) references 商品信息(商品编号) go
alter table 入库明细
add constraint FK_入库明细_RELATIONS_仓库foreign key (仓库编号) references 仓库(仓库编号) go
alter table 出库明细
add constraint FK_出库明细_RELATIONS_出库单foreign key (出库编号) references 出库单(出库编号) go
alter table 出库明细
add constraint FK_出库明细_RELATIONS_商品信息foreign key (商品编号) references 商品信息(商品编号) go
alter table 出库明细
add constraint FK_出库明细_RELATIONS_仓库foreign key (仓库编号) references 仓库(仓库编号) go
alter table 库存
add constraint FK_库存_库存_仓库foreign key (仓库编号) references 仓库(仓库编号) go
alter table 库存
add constraint FK_库存_库存_商品信息foreign key (商品编号) references 商品信息(商品编号) go
10
辽 宁 工 业 大 学 课 程 设 计 说 明 书(论 文)
3.2 存储过程及触发器设计代码
create trigger 入库明细_trigger on 入库明细for insert as
declare @a varchar(30),@b varchar(30) declare @d int,@e int
select @a=商品编号from inserted select @b=仓库编号from inserted select @d=入库数量from inserted
select @e=@d + (select 库存数量from 库存where 商品编号=@a and 仓库编号=@b) if @e >(select 库存上限from 库存where 商品编号=@a and 仓库编号=@b) begin
raiserror('超过库存上限,不能入库!',0,1) rollback end else begin
update 库存set 库存数量=库存数量+@d where 商品编号=@a and 仓库编号=@b end go
create trigger 出库明细_trigger on 出库明细for insert as
declare @a varchar(30),@b varchar(30) declare @d int,@e int
select @a=商品编号from inserted select @b=仓库编号from inserted select @d=出库数量from inserted
select @e=(select 库存数量from 库存where 商品编号=@a and 仓库编号=@b)-@d if @e <(select 库存下限from 库存where 商品编号=@a and 仓库编号=@b) begin
raiserror('低于库存下限,不能出库!',0,2) rollback end else begin
update 库存set 库存数量=库存数量-@d where 商品编号=@a and 仓库编号=@b end go
create trigger 借条_trigger on 借条信息for insert
11
辽 宁 工 业 大 学 课 程 设 计 说 明 书(论 文)
as
declare @a varchar(30),@b varchar(30) declare @d int,@e int
select @a=商品编号from inserted select @b=仓库编号from inserted select @d=借出数量from inserted
select @e=(select 库存数量from 库存where 商品编号=@a and 仓库编号=@b)-@d if @e <(select 库存下限from 库存where 商品编号=@a and 仓库编号=@b) begin
raiserror('低于库存下限,不能借出!',0,2) rollback end else begin
update 库存set 库存数量=库存数量-@d where 商品编号=@a and 仓库编号=@b end go
create trigger 还库_trigger on 借条信息for delete as
declare @a varchar(30),@b varchar(30) declare @d int,@e int
select @a=商品编号from deleted select @b=仓库编号from deleted select @d=借出数量from deleted
select @e=@d + (select 库存数量from 库存where 商品编号=@a and 仓库编号=@b) update 库存set 库存数量=库存数量+@d where 商品编号=@a and 仓库编号=@b go
create proc 库存_proc
(@a varchar(30),@b varchar(30)) as
select * from 库存
where 仓库编号=@a and 商品编号=@b VB设计部分界面及代码: 登陆界面:
12