《SQL数据库》试题(样例A)

loading 分享 2026-10-26 下载文档

[先行课程号] char(6) ) 4.

create table选课表 (ID IDENTITY(1, 1),

[学号] char(6) references 学生表(学号),

[课程号] char(6) references 课程表(课程号),

[分数] integer check([分数] between 0 and 100) ) 5.

insert 课程表 values('100001', 'C语言',2)

insert 课程表 values('100002', '数据结构', 2, '100001') insert 课程表 values('100003', '数据库原理', 2)

update课程表 set 课程名='SQL数据库' where 课程号='100003' delete课程表 where 课程号='100002'

6. create view [选课表视图] as

select 选课表.学号,姓名,选课表.课程号,课程名, 学分, 分数 from 选课表,学生表,课程表

where 选课表.学号=学生表.学号 and 选课表.课程号=课程表.课程号 --或

create view [选课表视图] as

select 选课表.学号,姓名,选课表.课程号,课程名, 学分,分数 from 选课表 join 学生表 on 选课表.学号=学生表.学号 join 课程表 on 选课表.课程号=课程表.课程号 7.

create function [某门课程成绩](@课程名 varchar(40))

returns table as

return (select学号,姓名,课程名,学分,分数from 选课表视图 where 课程名=@课程名) go

select * from [某门课程成绩]('SQL数据库') 8.

create procedure [某门课程高低均分]

@课程名 varchar(40) as

select 课程名, 最高分=max(分数)、最低分=min(分数)、平均分=avg(分数) from 选课表视图

where 课程名 = @课程名 go

————————————————————————————————————————————

execute [某门课程高低均分] 'SQL数据库' 9.

select 姓名, 学号, 专业 from 学生表

where 姓名 like '张%' and 性别='女' 10.

select 学号, 姓名, 专业 from 学生表 where学号 in (select distinct 学号 from 选课表 where分数<60) 11.

use [学生选课数据库]

exec sp_addlogin 'U领导', NULL, '学生选课数据库', '简体中文' exec sp_password NULL, '888', 'U领导' exec sp_grantdbaccess 'U领导', 'U读者'

exec sp_addrolemember 'db_datareader', 'U读者' --或

use [学生选课数据库]

exec sp_addlogin 'U领导', '888', '学生选课数据库' exec sp_grantdbaccess 'U领导', 'U读者'

exec sp_addrolemember 'db_datareader', 'U读者'

————————————————————————————————————————————


《SQL数据库》试题(样例A).doc 将本文的Word文档下载到电脑
搜索更多关于: 《SQL数据库》试题(样例A) 的文档
相关推荐
相关阅读