【正文】
tinyint not null, Quantity smallint not null, Date tinyint not null, PerCost float null, Finished tinyint not null constraint CKC_FINISHED_PURCHASE check (Finished in (0,1)), constraint PK_PURCHASEPLAN primary key (RawID) ) Go /*==============================================================*/ /* Table: ProducePlan */ /*==============================================================*/ create table ProducePlan ( ProductID tinyint not null, Quantity smallint not null, Finished tinyint not null constraint CKC_FINISHED_PRODUCEP check (Finished in (0,1)), constraint PK_PRODUCEPLAN primary key (ProductID) ) go /*==============================================================*/ /* Table: Product */ /*==============================================================*/ create table Product ( ProductID tinyint not null, Cost float not null, Quantity smallint not null, RDfund float not null, Owned tinyint not null constraint CKC_OWNED_PRODUCT check (Owned in (1,0)), RawCompose varchar(4) null, constraint PK_PRODUCT primary key (ProductID) ) go 采購(gòu)部門的存儲(chǔ)過程: 產(chǎn)品更新 create procedure Qupdate3 as declare id tinyint,dtype tinyint,isused tinyint ,procycle tinyint,owned tinyint declare cur cursor for select ID,[Type],IsUsed,Procycle,Owned from ProLine begin open cur fetch next from cur into id,dtype,isused,procycle,owned while(fetch_status=0) begin if owned=1 begin if isused=1 begin update ProLine set ProNow=ProNow+1 where ID=id if (select ProNow from ProLine where ID=id)=procycle begin update Product set Quantity=Quantity+1 where ProductID= (select ProductID from ProLine where ID=id) update ProLine set IsUsed=0 where ID=id update ProLine set ProNow=0 where ID=id end end end else begin if dtype=1 and (select [Value] from ProLine where ID=id)=5 update ProLine set Owned=1,[Value]=10000+[Value] where ID=id else if dtype=2 and (select [Value] from ProLine where ID=id)=8 update ProLine set Owned=1,[Value]=10000+[Value] where ID=id else if dtype=3 and (select [Value] from ProLine where ID=id)=16 update ProLine set Owned=1,[Value]=10000+[Value] where ID=id else if dtype=4 and (select [Value] from ProLine where ID=id)=24 update ProLine set Owned=1,[Value]=10000+[Value] where ID=id end fetch next from cur into id,dtype,isused,proc