Please turn in a PDF through Gradescope. You'll need to access Gradescope through Brightspace the first time (to register you for the course in Gradescope.) Gradescope is pretty self-explanatory, ITaP provides these instructions. Make sure that you mark the start/end of each question in Gradescope. Assignments will be graded based on what you mark as the start/end of each question. Please typeset your answers. (You won't be doing handwritten responses for a Google Project work request, why would you do so for class?)
Note:
Exercises with book numbers
are adapted from
Silberschatz, Korth & Sudarshan; while you are encouraged to
look there for further information (and may need to for some details)
please answer the question as asked below (they may not be exactly the
same.)
Given the following relational database instance:
CourseID | InstructorID | Name |
---|---|---|
CS448 | 7 | Introduction to Relational Database Systems |
CS580 | 14 | Algorithm Design, Analysis, And Implementation |
Student_id | CourseID | Grade | SectionNum | GroupID |
---|---|---|---|---|
1 | CS448 | A | 2 | 3 |
4 | CS448 | A | 1 | 2 |
5 | CS448 | B | 1 | 1 |
6 | CS448 | A | 1 | 1 |
9 | CS448 | B | 2 | 3 |
10 | CS448 | A | 2 | 4 |
11 | CS448 | C | 2 | 4 |
12 | CS448 | A | 2 | 3 |
13 | CS448 | A | 1 | 1 |
2 | CS580 | A | 1 | 1 |
3 | CS580 | A | 1 | 1 |
4 | CS580 | B | 1 | 2 |
6 | CS580 | A | 1 | 2 |
8 | CS580 | A | 1 | 2 |
10 | CS580 | A | 1 | 1 |
12 | CS580 | B | 2 | 3 |
15 | CS580 | A | 2 | 3 |
ID | Name | Nationality |
---|---|---|
1 | Jon Snow | USA |
2 | Jame Bond | UK |
3 | Winston Churchill | UK |
4 | Luke Skywalker | USA |
5 | Jackie Chan | China |
6 | Richard White | USA |
7 | Bruce Lee | USA |
8 | Hugo Lafayette | France |
9 | Ben Kenobi | USA |
10 | Harry Porter | UK |
11 | Son Goku | Japan |
12 | Wonder Woman | UK |
13 | Sun Tzu | China |
14 | Tony Stark | USA |
15 | Leia Organa | USA |
For each of the following queries, show the output when run on the above tables. Some may not be legal queries on the above relations, if not, explain why.
In addition to giving the results, provide an English description, SQL, and relational algebra (whichever two are not given) for each query.
SELECT P.Name, C.Name, E.Num FROM People as P, Courses as C, (SELECT CourseID, count(*) as Num FROM Enrollment GROUP BY CourseID) as E WHERE P.ID in (select C.InstructorID ) and C.InstructorID=P.ID and C.ID=E.CourseID;
SELECT Enrollment.GroupID, count(*) FROM Enrollment WHERE Enrollment.CourseID = ‘CS448’ GROUP BY Enrollment.GroupID having count(*)>2;
Richard White. Hint: You will likely need to use the rename operator ρ for the relational algebra version.
While you are encouraged to put these tables into a relational database (e.g., sqlite or mysql) and run the queries to check your answers, you should be able to figure figure out the anwers on your own. You may see similar questions on an exam (although with smaller tables), and you will not have the ability to use a machine to generate answers.
Write relational algebra for the following queries. If you need to make any particular assumptions, please list them.
CS44800.
F.
In the above schema, we list data types (domain) for each attribute. Do you need to know the domain to write the queries in the preceding question? Explain why or why not.
Union (X⋃Y) requires that the left (X) and right (Y) arguments have the same attributes with the same domains.
Each of the relations above has a primary key (underlined). For Course and Grades, the primary key consists of two attributes.
Suppose we wanted to find courses that do not have an instructor. Would the query Course ⋈Course.iid≠Instructor.iid Instructor do what we want? Explain why or why not.
Why do we need null values in a relational database? Create an example use case where nulls are appropriate, and a second example where there are nulls, but there would be a better way to set up the database so you didn't need to have nulls.
Why is intersection (⋂) not a basic relational operator? Explain with an example.