Database Principles and Applications Chapter 3 Homework

1. Multiple choice questions (20 questions in total, 60 points)

  1. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade).
    The option that can display "the participation of each athlete (including athletes who have not participated in any competition)" is ().

    A. SELECT Athlete.Athlete ID, Name, Team, Name, Results FROM Athlete INNER JOIN Competition INNER JOIN Item ON Athlete.Athlete ID=Competition.Athlete ID AND Competition.Item ID=Item.Item ID;

    B. SELECT Athlete.Athlete ID, Name, Team, Name, Results
    FROM Athlete, Project, Competition
    WHERE Athlete.Athlete ID=Competition.Athlete ID AND Event Item ID=Item.Item ID;

    C. SELECT athlete. Athlete number, name, team, name, performance
    FROM (athlete LEFT JOIN competition ON athlete. Athlete number = competition. Athlete number) LEFT JOIN item ON competition item number = item. Item number;

    D.SELECT Athlete.Athlete number, name, team, name, achievement
    FROM (athlete RIGHT JOIN competition ON athlete.Athlete number=competition.Athlete number) RIGHT JOIN item ON competition item number=item.item number;

  2. (Single-choice question, 3 points) Assume that there are 3 relationships, student relationship S, course relationship C, and student course selection relationship SC. Their structures are as follows: S(S_ID,S_NAME,
    AGE, DEPT)
    C(C_NO,C_NAME)
    SC( S_ID, C_NO, GRADE)
    where S_ID is the student ID, S_NAME, AGE is the age, DEPT is the department, C_NO is the course number, C_NAME is the course name, and GRADE is the grade. To retrieve the names and ages of all students who are older than "Li Jun", the correct SQL statement is ().
    A. SELECT S_NAME, AGE FROM S WHERE AGE > (SELECT AGE FROM S WHERES_NAME=‘李军’)
    B.SELECT S_NAME, AGE FROM S WHERE AGE > (S_NAME=‘李军’)
    C.SELECT S_NAME, AGE FROM S WHERE AGE > (SELECT AGE WHERES_NAME='李军’)
    D.SELECT S_NAME, AGE FROM S WHERE AGE > 李军.AGE

  3. (Single-choice question, 3 points) The correct option to create a non-clustered index T1 on "team" in the basic table "athlete" is ().
    A. CREATE NONCLUSTERED INDEX T1 ON team;
    B.CREATE INDEX T1 ON athlete (team);
    C.CREATE NONCLUSTERED INDEX T1 IN athlete (team);
    D. CREATE CLUSTERED INDEX T1 ON athlete (team);

  4. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade).
    The following option that can correctly query "the results of the competition events, the results are arranged in ascending order of the competition event number, and the results of the same competition event are arranged in descending order" is ().
    A.SELECT item number, result FROM game ORDER BY result, item number DESC;
    B.SELECT item number, result FROM game ORDER BY item number, result ASC;
    C.SELECT item number, result FROM game ORDER BY result DESC, item number ;
    D.SELECT item number, score FROM game ORDER BY item number, score DESC;

  5. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade).
    The following option that can correctly query "the athlete number and name of the female athlete from Jiangsu, Zhejiang and Shanghai" is ().
    A.SELECT project number, name FROM athlete WHERE team = ('Shanghai','Jiangsu','Zhejiang') AND gender='female;
    B.SELECT item number, name FROM athlete WHERE team IN ('Shanghai','Jiangsu','Zhejiang') AND gender='female;
    C.SELECT project number, name FROM athlete WHERE team = 'Shanghai' OR 'Jiangsu' OR 'Zhejiang' AND gender='female;
    D.SELECT project number, name FROM athlete WHERE team='Shanghai' OR team= 'Jiangsu' OR team = 'Zhejiang' AND gender = 'female;

  6. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade). The following option that can correctly query the "number of athletes who participated in the event" is ().
    A. SELECT COUNT(*) FROM match
    B.SELECT COUNT(DISTINCT player number) FROM game
    C.SELECT COUNT(DISTINCT *) FROM game
    D.SELECT COUNT(player number) FROM game;

  7. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade). The correct option to create the player view of the "Shanghai" team is ( ).
    A. CREATE VIEW SH_A AS SELECT Athlete No., Name, Gender FROM Athlete WHERE Team = 'Shanghai;
    B.CREATE VIEW SH_A SELECT Athlete No., Name, Gender FROM Athlete WHERE Team='Shanghai';
    C. CREATE VIEW SH_A(SH_NO,SH_NAME,SH_SEX) SELECT Athlete No., Name, Gender FROM Athlete WHERE Team='Shanghai;
    D.CREATE TABLE SH_A AS SELECT Athlete No., Name, Gender FROM Athlete WHERE Team='Shanghai;

  8. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade).
    The option that can correctly modify the venue and time of the "Women's 10m Diving" event is ().
    A.UPDATE project SET competition location='Wutaishan Gymnasium' AND competition time='2019-05-26 15:00:00' WHERE name='women's 10m diving';
    B.UPDATE project SET competition location='Wutaishan Gymnasium', competition time='2019-05-26 15:00:00' WHERE name='women's 10m diving';
    C.UPDATE competition location='Wutaishan Gymnasium', competition time='2019-05-26 15:00:00' SET project WHERE name='women's 10m diving; D.UPDATE
    competition location='Wutaishan Gymnasium', competition time ='2019-05-26 15:00:00' WHERE name='Women's 10m diving';

  9. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade).
    The option that can correctly query "the number, name, and team of participating players in basketball-related events" is ().
    A.SELECT Athlete.Athlete number, name, team FROM competition, athlete, project WHERE competition.Athlete number=item.Athlete number AND athlete.Project number=competition project number AND name LIKE '%basketball%';
    B.SELECT athlete.Athlete number, name, team FROM competition, athlete, project WHERE competition.Athlete number=athlete, athlete number AND project.Project number=competition project number AND name LIKE '%basketball%;
    C.SELECT player number, name, team FROM player, project WHERE name LIKE '%basketball%';
    D.SELECT player. player number, name, team FROM game, player, project WHERE game. player number = player. player id AND item.item_id=game,item_id AND name='%basketball%;

  10. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade).
    The option that can correctly "calculate the total points of each team and display the names and points of the top three teams" is ().
    A. SELECT TOP 3 teams, SUM (score) FROM game, athlete WHERE game. Athlete number = player. Player number GROUP BY team ORDER BY SUM (score); B. SELECT TOP 3 teams, SUM (score)
    FROM Competition,Athlete WHERE Competition.Athlete ID=Athlete.Athlete ID GROUP BY Team;
    C.SELECT TOP 3 Teams,SUM(Score) FROM Competition,Athlete WHERE Competition.Athlete ID=Athlete.Athlete ID ORDER BY SUM(Achievement) ;
    D.SELECT TOP 3 teams, SUM (score) FROM game, athlete WHERE game. Athlete number = athlete. Player number GROUP BY team ORDER BY 2 DESC;

  11. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade).
    The option that can correctly query the names of athletes who have participated in all events is ().
    A.SELECT name FROM athlete, competition, project WHERE athlete.Athlete ID = competition.Athlete ID AND item. Item ID = competition. Item ID;
    B.SELECT name FROM athlete WHERE NOT EXISTS (SELECT * FROM item WHERE NOT EXISTS (SELECT * FROM game WHERE athlete.athlete ID=competition.athlete ID AND item.item ID=competition.item ID));
    C.SELECT name FROM athlete WHERE EXISTS (SELECT * FROM item WHERE EXISTS (SELECT * FROM game WHERE athlete.athlete number = match.athlete number AND item.item number = match.item number)); D.SELECT name FROM athlete
    WHERE NOT EXISTS (SELECT * FROM game WHER E player. player number = game. player number);

  12. (Single-choice question, 3 points) Student course selection information table: sc(sno, cno, grade), the primary key is (sno, cno), the SQL statement to find out the tuples without grades from the student course selection information table is ().
    A. SELECT * FROM sc WHERE grade=NULL
    B. SELECT * FROM sc WHERE grade IS " "
    C. SELECT * FROM sc WHERE grade= ' '
    D. SELECT * FROM sc WHERE grade IS NULL

  13. (Single-choice question, 3 points) If you want to query all records that are greater than the minimum value in a certain subset, you should use the () operator in the WHERE clause.
    A.>ANY
    B.>ALL
    C.<ANY
    D.<ALL

  14. (Single-choice question, 3 points) To query all the books in the book table that contain "computer" in the title, you can use the () statement.
    A. select * from book where book_name like *computer*
    B. select * from book where book_name like '%computer%'
    C. select * from book where book_name = * computer *
    D. select * from book where book_name = '%computer%'

  15. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade).
    The options that can correctly query the "basic information of the competition on May 10, 2019" are (
    A.SELECT * FROM project WHERE competition time LIKE '2019-05-10_;
    B.SELECT * FROM project WHERE competition time LIKE '2019 -05-10\%' ESCAPE '\';
    C.SELECT * FROM item WHERE game time LIKE '2019-05-10%';
    D.SELECT * FROM item WHERE game time LIKE '2019-05-10\%;

  16. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade). The option that does not correctly insert a new athlete is ().
    A.INSERT INTO athlete (athlete number, name, gender, team) VALUES(js01029','Wang Chong','male',Jiangsu);
    B.INSERT INTO athlete VALUE(js01029','Wang Chong','male','Jiangsu');
    C. INSERT INTO athlete VALUES(js01029','Wang Chong','male''Jiangsu');
    D.INSERT INTO athlete (name, athlete number, team, gender) VALUES('Wang Chong','js01029', 'Jiangsu','male');

  17. (Single-choice question, 3 points) There is a table St_info in the database db_student: student number (Sno), name (Sname), gender (Ssex), age (Sborn), department (Sdept), where Sno is the primary key, and other fields Both are allowed to be empty. To query the number of all girls should use ().
    A.SELECT COUNT(*) FROM St_info WHERE Ssex='女
    B.SELECT COUNT(Ssex='女) FROM St_info
    C. SELECT COUNT(*) FROM St_info GROUP BY Ssex
    D.SELECT COUNT(Sname) FROM St_info WHERE Ssex='女

  18. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade).
    The option to correctly find out the names of athletes from other teams whose performance is higher than all athletes from the Jiangsu team in the "men's 10-meter diving" competition is ().

    A.SELECT Name, Team FROM Athlete, Competition, Project WHERE Athlete.Athlete ID = Competition. Athlete ID
    AND Item. Item ID = Competition. Item ID AND Name = 'Men's 10m Diving' AND Team<>'Jiangsu'
    AND Result< ALL (SELECT Result FROM Athlete, Competition, Project WHERE Athlete. Athlete ID = Competition. Athlete ID AND Item. Item ID = Competition. Item ID AND Name = 'Men's 10-meter Diving' AND Team = 'Jiangsu') ;

    B.SELECT Name, Team FROM Athlete, Competition, Project WHERE Athlete. Athlete ID = Competition. Athlete ID AND Item. Item ID = Competition. Item ID AND Name = 'Men's 10-meter Diving' AND Team <> 'Jiangsu' AND result> ANY(SELECT result FROM athlete, competition, project
    WHERE athlete.Athlete ID=competition.Athlete ID AND item.Event ID=competition item ID AND name='men's 10m diving' AND team='Jiangsu);

    C.SELECT name, team FROM athlete, competition, project
    WHERE athlete.athlete number = competition.athlete number AND project item number=competition.item number AND name='men's 10-meter diving' AND team<>'Jiangsu' AND Score> (SELECT MAX(score) FROM athlete, competition, project WHERE athlete. Athlete number = competition. Athlete number AND project. Project number = competition. Project number AND name = 'men's 10-meter diving' AND team = 'Jiangsu) ;

    D.SELECT Name, Team FROM Athlete, Bihan, Project
    WHERE Athlete.Athlete ID=Competition.Athlete ID AND Item Item ID=Competition Item ID AND Name='Men's 10m Diving' AND Score> (SELECT MAX(Score) FROM athlete, competition, project WHERE athlete.Athlete ID=competition.Athlete ID AND item.Item ID=competition item ID AND name='men's 10m diving' AND team category='Jiangsu');

  19. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition place and time), competition (athlete number, event number, score). The option that can correctly query "the name of the event that has not yet specified the competition venue and time" is ().
    A.SELECT name FROM item WHERE game location=' ' AND game time=' ';
    B.SELECT name FROM item WHERE game location=NULL AND game time=NULL;
    C.SELECT name FROM item WHERE game location='NULL' AND game time = 'NULL';
    D.SELECT name FROM item WHERE game location IS NULL AND game time IS NULL;

  20. (Single-choice question, 3 points) Part of the basic table of a sports meeting management system database: athlete (athlete number, name, gender, team), event (event number, name, competition location, competition time), competition (athlete number, item number, grade).
    The option that cannot correctly find out the numbers and names of athletes participating in the "Men's Table Tennis Singles" competition is ().

    A.SELECT player number, name FROM player
    WHERE player number = (SELECT player number FROM game, project WHERE project. project number = game. project number AND name = 'men's table tennis singles');

    B.SELECT player number, name FROM player
    WHERE EXISTS (SELECT * FROM game, item WHERE item. item number = game. item number AND name = 'men's table tennis singles' AND player. player number = game. player number)

    C.SELECT Athlete No., Name FROM Athlete, Competition, Project
    WHERE Athlete.Athlete No. = Competition. Athlete No. AND Project. Project No. = Competition Item No. AND Name='Men's Table Tennis Singles;

    D.SELECT player number, name FROM player WHERE player number IN (SELECT player number FROM game, project WHERE project. project number = game. project number AND name = 'men's table tennis singles);

2. Short answer questions (2 questions in total, 40 points)

  1. (Short answer questions, 10 points)
    There is a student form S(SNO,SN) (SNO is the student number, SN is the name) and a student course selection form SC(SNO,CNO,CN,G) (CNO is the course number, CN is the course name, G is the grade), try the SQL language to complete the following questions:
    (1). Create a view V-SSC (SNO, SN, CNO, CN, G), and sort by CNO ascending order;
    (2). From the view V - Query SN, CN and G with an average score above 90 on the SSC.

Correct answer:
(1).

CREATE VIEWV-SSC(SNO,SN,CNO,CN,G)
AS SELECT S.SNO, S.SN,CNO,SC.CN,SC.G
FROM S,SC
WHERE S.SNO=SC.SNO
ORDER BY CNO

(2).

SELECT SN,CN,G
FROM V-SSC
GROLIP BY SNO
HAVING AVG(G)>90
  1. (Short answer question, 30 points) There are three relationships in the student course database:
    student relationship S (S#, SNAME, AGE, SEX) learning relationship SC (S#, C#, GRADE) course relationship C (C#, CNAME) where
    S #, C#, SNAME, AGE, SEX, GRADE, and CNAME represent student number, course number, name, age, gender, grade, and course name respectively. Use SQL statements to express the following operations
    (1) Retrieve the student ID and name of the students whose elective course name is "MATHS"
    (2) Retrieve the student IDs of students who have studied at least the course IDs "C1" and "C2"
    (3) Retrieve The student number, name and age of girls aged between 18 and 20 (including 18 and 20)
    (4) Retrieve the student ID and average grade of students with an average score of more than 80 points
    (5) Retrieve the names of students who have taken all courses
    ( 6) Retrieve the names of students who have taken more than three courses

正确答案:
(1)SELECT S#, SNAME FROM S,SC,C WHERE S.S#=SC.S# AND C.C#=SC.C# AND CNAME=‘MATHS’
(2) SELECT S# FROM SC WHERE C#=‘C1’ AND S# IN ( SELECT S# FROM SC WHERE C#=C2’)
(3) SELECT S#, SNAME,AGE FROM S WHERE SEX=‘女’ AND AGE BETWEEN 18 AND 20
(4) SELECT S#, AVG(GRADE) ‘平均成绩’ FROM SC GROUP BY S# HAVING AVG(GRADE)>80
(5) SELECT SNAME FROM S WHERE NOT EXISTS(SELECT*FROM C
WHERE NOT EXISTS (SELECT * FROM SC WHERE S#=S.S# AND C#=C.C#))
(6) SELECT SNAME FROM S,SC WHERE S.S#=SC.S# GROUP BY SNAME HAVING COUNT(*)>3

Guess you like

Origin blog.csdn.net/qq_46373141/article/details/131245135