資料庫綜合實驗報告

2021-04-22 08:39:14 字數 2976 閱讀 6628

《資料庫實務》

(2014——2015學年第2學期)

學院數學與資訊學院

學號 1214010105

姓名周毅仁

授課教師那麗春

填表日期:2023年6月2日

作業要求:

利用teaching資料庫進行觸發器、儲存過程、t-sql的綜合練習

一、建立1個有實際意義的儲存過程。

1、儲存過程功能描述:

2、儲存過程建立語句:

3、呼叫儲存過程語句:

二、建立1個有實際意義的觸發器。

1、觸發器功能描述:每當在teacher表中插入資料,顯示表中所有資料

2、觸發器建立語句:

useteaching;

gocreatetriggert

onteacherforinsert

asbegin

if (columns_updated()&1=1)

select*fromteacher

end3、觸發器觸發語句:

forinsert

asbegin

if (columns_updated()&1=1)

三、完成2個t-sql的綜合練習題目:要求最少使用1迴圈,1個選擇結構。至少使用3個函式。

1、語句功能描述:

2、t-sql語句:

3、觸發器觸發語句:

語句功能:查詢給定課程給定成績段學生的資訊

t-sql語句:

alterprocjudge_st

@coursenonchar(6),@levelnchar(2)

asif(@level='a')

selectdistinctstudentno,sname,courseno,final

fromst_score

wherecourseno=@coursenoandfinal>90

elseif(@level='b')

selectdistinctstudentno,sname,courseno,final

fromst_score

wherecourseno=@coursenoandfinal>80 andfinal<=90

elseif(@level='c')

selectdistinctstudentno,sname,courseno,final

fromst_score

wherecourseno=@coursenoandfinal>70 andfinal<=80

elseif(@level='d')

selectdistinctstudentno,sname,courseno,final

fromst_score

wherecourseno=@coursenoandfinal>60 andfinal<=70

execjudge_st@courseno='c05109',@level='d'

語句功能描述:根據性別給學生分配寢室,4人一間

t-sql語句:

declarecursor_stcursorfor

select*fromstudent

print學生寢室號

print

print'|學生編號 |學生姓名 |性別|寢室號'

print

declare@studentnoasnchar(10),@snameasnchar(8),@***asnchar(1),@birthdayasdatetime,@classnoasnchar(6),@pointasnchar(6),@phoneasnchar(12),@emailasnchar(20)

declare@dorm_basint,@dorm_gasint,@count_basint,@count_gasint

set@dorm_b=61001

set@dorm_g=71001

set@count_b=0

set@count_g=0

opencursor_st

fetchnextfromcursor_stinto@studentno,@sname,@***,@birthday,@classno,@point,@phone,@email

while@@fetch_status=0

begin

if(@***='男')

begin

if(@count_b<4)

begin

set@count_b=@count_b+1

print'|'+cast(@studentnoasnchar(10))+'|'+cast(@snameasnchar(8))+'|'+cast(@***asnchar(2))+'|'+cast(@dorm_basnchar(6))+'|'

fetchnextfromcursor_stinto@studentno,@sname,@***,@birthday,@classno,@point,@phone,@email

endelse

begin

set@count_b=0

set@dorm_b=@dorm_b+1

endend

else

begin

if(@count_g<4)

begin

set@count_g=@count_g+1

print'|'+cast(@studentnoasnchar(10))+'|'+cast(@snameasnchar(8))+'|'+cast(@***asnchar(2))+'|'+cast(@dorm_gasnchar(6))+'|'

fetchnextfromcursor_stinto@studentno,@sname,@***,@birthday,@classno,@point,@phone,@email

endelse

begin

set@count_g=0

set@dorm_g=@dorm_g+1

endend

endclosecursor_st

deallocatecursor_st

資料庫實驗報告

資料庫系統概論 實驗報告 實驗三 sql單錶查詢和多表查詢 一 實驗目的 1 觀察查詢結果,體會select語句實際應用 2 要求學生能夠在access環境中使用select語句進行簡單查詢 資料排序和資料連線查詢的操作方法 二 實驗準備 本實驗需要用到實驗一所建立的 學生成績管理 的資料庫和stu...

資料庫實驗報告

資料庫原理 實驗報告 東北大學秦皇島分校 4.在查詢分析器中按照下列要求修改第3題中建立的資料庫test2 1 主要資料檔案的容量為2mb,最大容量為20mb,增幅為2mb。2 次要資料檔案的容量為2mb,最大容量為20mb,增幅為2mb。事務日誌檔案的容量為1mb,最大容量為10mb,增幅為2mb...

資料庫實驗報告

實驗三雙埠儲存器的設計與實現實驗報告 1137030 趙藝灣 一 實驗目的 1 掌握 quartus 中利用巨集功能模組設計儲存器的方法 2 掌握儲存器模組的讀寫時序和模組擴充套件方法 3 進一步熟悉 verilog hdl 語言設計電路的方法 二 實驗裝置 pc 機 quartus 10.0 fp...