【正文】
e from student Open s_cursor Fetch next from s_cursor into sno, sname While fetch_status =0 Begin Print ‘學生列表:’ Select mess=’學號:’ +sno+’, 姓名:’ +sname Print mess Fetch next from s_cursor into sno, sname end close s_cursor deallocate s_cursor 觸發(fā)器create trigger trigfor on sc for insert asdeclare o char(8) select o=o from inserted if o not in (select o from c) begin print 39。rollback transactionend 六、實驗小結(jié)自己寫課程名:數(shù)據(jù)庫應用與開發(fā) 時間:實驗八 自定義函數(shù)一、實驗目的與要求 熟悉函數(shù)的使用掌握游標的概念及使用二、實驗器材微機+windows操作系統(tǒng)+SQL SERVER2008+iis三、實驗內(nèi)容用getdate()和datepart()函數(shù)實現(xiàn)查詢學生的出生年份用left()函數(shù)查詢姓王的學生信息創(chuàng)建一個計算機系的游標,用fetch方式實現(xiàn)數(shù)據(jù)的推進創(chuàng)建一游標查詢各門課程前三名的學生成績表四、實驗步驟 進入sql server 2008 選擇SSMS 附加數(shù)據(jù)庫新建查詢,分析運行以上試題五、實驗結(jié)果Select datepart(getdate()) from s select * from s where left(sn)=’王’declare mycursor2 scroll cursorfor select * from studentwhere depart=39。open mycursor2fetch next from mycursor2declare o char(8)declare mycursor scroll cursorforselect o from courseopen mycursorfetch next from mycursor into owhile(fetch_status=0)beginprint39。+o+39。select top 3* from sc where o=o order by grade descfetch next from mycursor into oendclose mycursordeallocate mycursor六、實驗小結(jié)