- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
《 数 据 库 系 统 与 应 用 》 上 机 习 题
***************************************************************************
**********************
第五部分、 SQL 高级应用
要求掌握: 熟练掌握 T-SQL语言, 了解异常处理的相关语句, 学会用游标方式对数据
库进行操作。
一、 做书上第十章的例题
二、 写出书上 198页练习题 10中第7、8、9、11题的结果, 并上机验证。 完成第 12、13、
14题
7、数据库中没有 stud表
8、
9、重复插入 ID的值
11、
12、编写一个程序 ,采用游标的方式输出所有课程的平均分
use school
go
set nocount on
declare @s_cj int ,@s_namechar(8)
declare c_cursor cursor for
select score.课程号 ,AVG (score.分数 )
from score
group by score.课程号
order by score.课程号
open c_cursor
fetch next from c_cursor into @s_cj,@s_name
while @@FETCH_STATUS=0
begin
print CAST(@s_cj as char(8))+@s_name
fetch next from c_cursor into @s_cj,@s_name
end
close c_cursor
deallocate c_cursor
go
13、编写一个程序,使用游标的方式输出所有学号,课程号,成绩等级
use school
declare @s_xh int ,@c_name char(8),@s_cjfloat ,@dj char(1)
declare c_cursor cursor for
select student .学号 ,score.课程号 ,score.分数
from score,student
where score.学号 =student .学号
group by student .学号 ,score.课程号 ,score.分数
order by student .学号
begin
set @dj=CASE
when @s_cj=90 then A
when @s_cj=80 then B
when @s_cj=70 then C
when @s_cj=60 then D
else E
end
open c
fetch next from c_cursor into @s_xh,@c_name,@s_cj
print 学号 课程号 等级
print
while @@FETCH_STATUS=0
begin
print @s_xh+ +@c_name+ +@s_cj
fetch next from c_cursor into @s_xh,@c_name,@s_cj
end
close c_cursor
deallocate c_cursor
14、编写一个程序,输出各班各课程的平均分
use school
go
set nocount on
declare @s_cj int ,@s_namechar(8),@s_bj char(8)
declare c_cursor cursor for
select student .班级 ,score.课程号 ,AVG (score.分数 )
from score,student
group by score.课程号 ,student .班级
order by score.课程号 ,student .班级
open c_cursor
fetch next from c_cursor into @s_cj,@s_name,@s_bj
print 学号 班级 成绩
print
while @@FETCH_STATUS=0
b
文档评论(0)