设在学生数据库中有三张表,表结构如下所示: Student(学生表): Student表的主键:sno(学号) Course(课程

设在学生数据库中有三张表,表结构如下所示:
Student(学生表):

Student表的主键:sno(学号)
Course(课程表)

课程表的主键:cno(课程号)
S_C(成绩表)

成绩表的主键:(sno,cno)
成绩表的外键:sno,其值取自学生表的主键sno
cno,其值取自课程表的主键cno
写出实现以下功能的SQL语句
(1)创建成绩表S_C(表名和属性名必须用英文书写)。
(2)在学生表中,插入一条不完整记录(‘1010’,’李小丽’,‘女’)。
(3)在课程表中创建关于“课程名称”的索引。
(4)将学号为‘1005’的学生年龄修改为23岁。
(5)将“管理信息系统”这门课从课程表中删除。
(6)查询李元老师所教课程的课程号,课程名称和学时,并按课程号的降序排列。
(7)查询每个学生的总分。
(8)为学生表中所有年龄在18到24岁的男生创建一个视图。
(9)查询选修了课程号为“001”的学生的学号和姓名(用子查询实现)。
(10)查询选修了课程名称为“关系数据库”的学生学号和姓名(用连接查询实现)。
(11)查询选修课程数超过3门学生姓名。
(12)查询既选修课程号为“002”,又选修课程号为“004”的学生的姓名

第1个回答  推荐于2017-12-16
(1) create table S_C
(sno char(10) not null
,cno char(8) not null
,score int null
,constraint PK_SC primary key (sno,cno)
)
(2)insert into Student (sno,sname,ssex)
values('1010','李小丽','女')
(3)create index IND_CName on Course (cname)
(4)update student set sage=23 where sno='1005'
(5)delete from course where cname='管理信息系统'
(6)select cno,cname,ctime
from course
where teacher='李元'
order by cno ASC
(7)select sno,sum(score) as score
from S_C
group by sno
(8)create view V_Student
as
select *
from student
where ssex='男' and sage>=18 and sage<=24
(9)select sno,sname
from student
where sno in (select sno from S_C where cno='001')
(10)select A.sno,A.sname
from student A
left join S_C B on A.sno=B.sno
left join Course C on B.cno=C.cno
where C.cname='关系数据库'
(11)select sno,sname from
(select A.sno,A.sname,count(1) as count_
from student A
left join S_C B on A.sno=B.sno
group by A.sno,A.sname) A
where count_>3
(12)select C.sname
from
(select * from S_C where cno='002') A
inner join
(select * from S_C where cno='004' on) B on A.sno=B.sno
left join student C on A.sno=C.sno本回答被提问者采纳
相似回答