【正文】
ch next from s_cursor into @sno, @sname While @@fetch_status =0 Begin Print ‘學(xué)生列表:’ Select @mess=’學(xué)號:’ +@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。該課程信息不存在,不允許插入選修記錄39。rollback transactionend 六、實(shí)驗(yàn)小結(jié)自己寫課程名:數(shù)據(jù)庫應(yīng)用與開發(fā) 時間:實(shí)驗(yàn)八 自定義函數(shù)一、實(shí)驗(yàn)?zāi)康呐c要求 熟悉函數(shù)的使用掌握游標(biāo)的概念及使用二、實(shí)驗(yàn)器材微機(jī)+windows操作系統(tǒng)+SQL SERVER2008+iis三、實(shí)驗(yàn)內(nèi)容用getdate()和datepart()函數(shù)實(shí)現(xiàn)查詢學(xué)生的出生年份用left()函數(shù)查詢姓王的學(xué)生信息創(chuàng)建一個計(jì)算機(jī)系的游標(biāo),用fetch方式實(shí)現(xiàn)數(shù)據(jù)的推進(jìn)創(chuàng)建一游標(biāo)查詢各門課程前三名的學(xué)生成績表四、實(shí)驗(yàn)步驟 進(jìn)入sql server 2008 選擇SSMS 附加數(shù)據(jù)庫新建查詢,分析運(yùn)行以上試題五、實(shí)驗(yàn)結(jié)果Select datepart(getdate()) from s select * from s where left(sn)=’王’declare mycursor2 scroll cursorfor select * from studentwhere depart=39。計(jì)算機(jī)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。以下是39。+@o+39。的前三名同學(xué)的成績表39。select top 3* from sc where o=@o order by grade descfetch next from mycursor into @oendclose mycursordeallocate mycursor六、實(shí)驗(yàn)小結(jié)