【正文】
ntity)UPDATE Supply SET quantity=quantity@quantityWHERE ProviderID=@prividerID AND partID=@partIDIF (SELECT quantity FROM Supply WHERE Proiderid=@provider AND partID=@PartID)0 ROLLBACK TRANSACTlON @TranSNameDELETE FROM Supply WHERE quantity=0UPDATE OfferToBuy SET quantity=quanttity@quantityWHERE CustomerID=@customerid AND partlD=@partIDIF(SELECT quandtity FROM OfferToBuy WHERE CustomerID=@CustomerID AND partID=@partlD)0 ROLLBACK TRANSACTION @TransNameDELETE FROM OfferToBuy WHERE quantity=0COMMIT TRANSACTION @TransName 為了使用方便,這里定義了一個存貯過程;功能是完成從Agreementt的一個元組到Business的一個元組的轉(zhuǎn)化工作。這里考慮到了刪除空的Suppiy和OfferTOBUY項,更加重要的是,這里考慮到了非法的Agreement的情況,在一段時間后,由于供應商或者顧客修改數(shù)據(jù),Agreement可能就非法,這時就需要把這個事務廢除,所以,這里檢查了Supply表和OfferToBuy表中的數(shù)據(jù),確保數(shù)據(jù)仍然正確。 另外交易員,或者說交易所必須承擔的一項任務是更新零件列表。這里在考慮顧客和供應商的時候247。并沒有給予他們修改零件列表的權利,所以他們必須根據(jù)數(shù)據(jù)庫中已有的項更新自己的供求信息。 由于這個數(shù)據(jù)庫實際上更加偏重于模型化,而不是一個實際環(huán)境中的數(shù)據(jù)庫,所以在實現(xiàn)應用模型的時候我們還需要對這個數(shù)據(jù)庫的模型作一些修改。 由于本實驗在模型設計上使用了Microsoft TransactSQL的語法,因此以上的數(shù)據(jù)庫操作都是在SQLSERVER2000上測試通過的。[實驗數(shù)據(jù)示例:測試階段]( ,查找錯誤校正錯誤,檢查是否符合用戶的功能性能要求)1.實驗方案設計(1)輸入數(shù)據(jù)設計:1)插入零件信息; insert into Part(Color,Name,Weight,Intro) values(39。black39。,39。stick39。,39。3039。,39。of steel39。);顯示剛插人的零件id: select id from Part where name=39。stick39。; id 1 (1 row(s) affected)(不同的實驗,id值可能不同。以后相應操作要保持前后一致就可以丁。)2)插入供應商信息: insert into Provider(Name,password,Address,Tel,Intro) values(39。l39。,39。123439。,39。北京39。,6543210,39。nothing39。);顯示剛插入的供應商id: select id from Provider where name=39。l39。; id 1 (1 row(s) affected)3)插入顧客信息: insert into Customer(Name,Address,Tel) values(39。cusl39。,39。北京39。,39。666666639。)39。顯示剛插入的顧客id: select id from Customer where name id 1 (1 row(S)affected)4)插入供應商供應信息: insert into Supply(PartID,ProviderlD,Price,Quantity) values(1,1,20,100);5)插入顧客需求信息: insert into OfferToBuy(PartlD,CustomerID,Priee,Quantity) values(1,1,20,50);6)插入?yún)f(xié)議信息: insert into Agreement(CustomerID,ProviderID,PartlD,Price,Quantity,CustomerSign,ProviderSign) values(1,1,1,20,30,1,1);(2)執(zhí)行交易操作設計: 1)執(zhí)行交易存儲過程PASS_AGREEMENT,參數(shù)為:1,1,1:PASS_AGREEMENT 1,1,1。 (后面的三個參數(shù)分別對應前面選擇出的供應商ID、顧客ID和零件ID。)2)結果:顯示交易后供應信息和需求信息: select Quantity from Supply where PartlD=1 and ProviderlD=1。 Quantity 70 (1 row(s) affected) select Quantity from OfferToBuy where PartlD=l and CustomerID; Quantity 20 (1 row(s) affected) 3)分析結果: 首先,保存在Supply表中1D為1的零件供應量為100(參見Supply表的Insert語句),保存在OfferToBuy表中ID為1的零件需求量為50(參見OFFERToBuy表的Insert語句)。在Agreement表中指出ID為1的供應商和ID為1的顧客要交易30個ID為1的零件。當執(zhí)行存儲過程PASS_AGREEMENT之后,Supply和OfferToBuy表中相應的數(shù)量都減少了30,交易成功。4)再次執(zhí)行交易操作:delete from Busines