第5章习题与参考答案
一。单项选择题
1。当关系R与S进行连接操作时,如果R中得元组不满足连接条件,在连接结果中也会将这些记录保留下来得操作就是(A).
A.左外连接
B。右外连接
C.内连接
D.自连接
2。下列聚合函数中,不忽略空值得就是(D).
A。SUM(列名)
B。MAX(列名)
C。AVG(列名)
D。COUNT(*)
3.下列查询语句中,错误得就是(B).
A。SELECT Sno, COUNT(*) FROM SC GROUP BY Sno
B。SELECT Sno FROM SC GROUP BY Sno WHERE COUNT(*) > 3
C。SELECT Sno FROM SC GROUP BY Sno HAVING COUNT(*) > 3
D.SELECT Sno FROM SC GROUP BY Sno
4.现要利用Student表查询年龄最小得学生姓名与年龄。下列实现此功能得查询语句中,正确得就是(D)。
A.SELECT Sname, MIN(Sage) FROM Student
B。SELECT Sname, Sage FROM Student WHERE Sage = MIN(Sage)
C。SELECT TOP 1 Sname, Sage FROM Student
D.SELECT TOP 1 Sname, Sage FROM Student ORDER BY Sage
5.设SC表中记录成绩得列为:Grade,类型为int.若在查询成绩时,希望将成绩按‘优'、‘良’、‘中’、‘及格'与‘不及格’形式显示,正确得Case函数就是(C)。
A.Case Grade
When 90~100THEN’优’
When 80~89THEN'良’
When 70~79THEN’中'
When 60~69THEN'及格’
Else’不及格'
End
B。Case
When Gradebetween 90 and 100THENGrade = '优’
When Gradebetween 80 and 89THENGrade = ’良’
When Gradebetween 70 and 79THENGrade = ’中'
When Gradebetween 60 and 69THENGrade = ’及格’
ElseGrade = '不及格'
End C。Case
When Gradebetween 90 and 100THEN'优'
When Gradebetween 80 and 89THEN'良’
When Gradebetween 70 and 79THEN’中’
When Gradebetween 60 and 69THEN’及格’
Else’不及格'
End
D。Case Grade
When 90~100THEN Grade = ’优’
When 80~89THEN Grade = '良’
When 70~79THEN Grade = ’中'
When 60~69THEN Grade = ’及格'
ElseGrade = '不及格’
End
6.下列SQL语句中,用于修改表数据得语句就是(C)。
A.ALTER
B。SELECT
C。UPDATE
D.INSERT
7。设有Teachers表,该表得定义如下:
CREATE TABLE Teachers(
Tno CHAR(8) PRIMARY KEY,
Tname VARCHAR(10) NOT NULL,
Age TINYINT CHECK(Age BETWEEN 25 AND 65) )
下列插入语句中,不能正确执行得就是(D).
A。INSERT INTO Teachers VALUES(’T100’,’张宏’,NULL)
B。INSERT INTO Teachers(Tno,Tname,Age) VALUES(’T100’,’张宏',30)
C。INSERT INTO Teachers(Tno,Tname) VALUES(’T100’,'张宏')
D.INSERT INTO Teachers VALUES(’T100’,’张宏’)
8。设数据库中已有教材中得Student(Sno,Sname,Ssex,Sage,Sdept)、Course(Cno,Cname,Credit,Semster)与SC(Sno,Cno,Grade)表。现要查询学生选得第2学期开设课程得情况,只需列出学号、姓名、所在系与所选得课程号。该查询涉及到得表就是(D)。
A。仅Student表
B。仅Student与SC表
C.仅Student与Course表
D。Student、SC与Course表
9.下列删除计算机系学生(在student表中)得修课记录(在SC表中)得语句,正确得就是(B).
A。DELETEFROM SC JOIN Student b ON S、Sno = b、Sno
WHERE Sdept = ’计算机系’
B。DELETE FROM SC FROM SC JOIN Student b ON SC、Sno = b、Sno
WHERE Sdept = '计算机系'
C。DELETE FROM StudentWHERE Sdept = '计算机系’
D.DELETE FROM SC WHERE Sdept = ’计算机系'
二.判断题
1。SELECT * FROM Student WHERE Sname LIKE’张_'语句中得’张_' 用于查找姓张得学生。(╳)
2。SELECT * FROM Student WHERE Sname LIKE'[张李刘]%' 语句可以查找姓张、李、刘得学生。(√ )
3。SELECT COUNT(DISTINCT Sno) FROM SC 语句用于统计学生得总人数。(╳)