實驗三:數(shù)據(jù)庫編程_第1頁
實驗三:數(shù)據(jù)庫編程_第2頁
實驗三:數(shù)據(jù)庫編程_第3頁
實驗三:數(shù)據(jù)庫編程_第4頁
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)

文檔簡介

1、數(shù)據(jù)庫原理實驗報告(三)成績實驗名稱數(shù)據(jù)庫編程姓名學(xué)號班級實驗?zāi)康?1) 了解存儲過程、函數(shù)和觸發(fā)器的作用;(2) 熟悉使用命令創(chuàng)建存儲過程的方法;(3) 熟悉使用命令創(chuàng)建函數(shù)的方法;(4) 熟悉使用命令創(chuàng)建觸發(fā)器的方法。實驗內(nèi)容(1) 創(chuàng)建一個函數(shù),以工程號為參數(shù),返回該工程所在的城市,如果沒有該工程,返回“無此工程”。create function ret_city(jno char(2)returns char(20)asbegin declare city char(20); if not exists (select * from j where jno= jno) set city

2、=無此工程; else select city=city from j where jno= jno; return city;end(2) 創(chuàng)建一個函數(shù),以供應(yīng)商號為參數(shù),返回該供應(yīng)商供應(yīng)零件的總數(shù)量。如果不存在該供應(yīng)商,則返回-100。create function ret_sl(sno char(2)returns intasbegin declare total_qty int; if not exists (select * from s where sno= sno) set total_qty=-100; else select total_qty =sum(qty) from

3、spj where sno= sno; return total_qty;end(3) 創(chuàng)建一個存儲過程,以供應(yīng)商號、工程號、零件號、供應(yīng)量為參數(shù),在SPJ表中插入一條記錄,如果該記錄已存在,顯示“記錄已存在!”,否則顯示“插入成功!”。Create PROCEDURE insert_1 sno char(2),pno char(2),jno char(2),qty intAS begin if exists (select * from spj where sno= sno and pno= pno and jno= jno and qty=qty) Print 記錄已存在!; else b

4、egin insert into spj values(sno,pno,jno,qty); print 插入成功! end end(4) 創(chuàng)建一個存儲過程,以供應(yīng)商號、工程號、零件號、供應(yīng)量(新)為參數(shù),修改SPJ表中某供應(yīng)商給某工程供應(yīng)某零件的供應(yīng)量為新供應(yīng)量,如果不存在該記錄,則顯示“無此記錄!”,否則顯示“修改成功!”。Create PROCEDURE update_1 sno char(2),pno char(2),jno char(2),qty intAS begin if not exists (select * from spj where sno= sno and pno= p

5、no and jno= jno) Print 無此記錄!; else begin update spj set qty=qty where sno= sno and pno= pno and jno= jno; print 修改成功! end end(5) 創(chuàng)建一個存儲過程,以工程號為參數(shù),刪除J表及SPJ表中相應(yīng)的記錄,如果不存在該工程,顯示“無此工程!”;如果該工程沒有零件供應(yīng)記錄,顯示“該工程沒有供應(yīng)記錄,J表中記錄已刪除!”;如果該工程有零件供應(yīng)記錄,顯示“已刪除J表及SPJ表中的記錄!”。Create PROCEDURE delete_1 jno char(2)AS begin if

6、 not exists (select * from j where jno= jno) Print 無此工程!; else if not exists (select * from spj where jno= jno) begin delete from j where jno= jno; print 該工程沒有供應(yīng)記錄,J表中記錄已刪除! end else begin delete from spj where jno= jno; delete from j where jno= jno; print 已刪除J表及SPJ表中的記錄! end end(6) 創(chuàng)建入庫表出庫表上的六個觸發(fā)器。

7、入庫修改:create trigger updat_rk on tab_rkfor updateasbegin declare old_spbh int declare old_rksl int declare new_spbh int declare new_rksl int select old_spbh=spbh from deleted select old_rksl=rksl from deleted select new_spbh=spbh from inserted select new_rksl=rksl from inserted if old_spbh=new_spbh and old_rksl!=new_rksl begin update tab_kc set kcl=kcl - old_rksl + new_rksl where spbh=new_spbh; return; end if old_spbh!=new_spbh begin update tab_kc set kcl=kcl - old_rksl where spbh=old_spbh; if exists(select * from tab_kc where spbh=ne

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論