

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


(a) Please express Division using the five basic relational operators. As with the example in class, let us denote division by A/B where A = {x,y} and B={y}. For simplicity, assume that x, y are two attributes. (b) The Semijoin of relations R and S, denoted R < S, is the set of tuples of R(a 1 , a 2 , …, an) that agree with at least one tuple of S on all attributes that are common to the schemas of R and S. Give an expression of the relational algebra that is equivalent to R < S.
Consider the schema below. student ( snum :integer, sname :char(30), major :char(25), standing :char(2), age :integer) faculty ( fid :integer, fname :char(30), deptid :integer) class ( name :char(40), meets_at :char(20), room :char(10), fid :integer | fid REFS Faculty. fid ) enrolled ( snum :integer, cname :char(40) | snum REFS student. snum , cname REFS class. name ) Write the following queries in relational algebra: Q1) Retrieve the snum of students who have taken two different classes. Please only return distinct values of snum. Q2) Retrieve the snum and sname of students who have taken a class from ‘Ivana Teach’ or ‘Linda Davis’. Q3) Retrieve the snum and sname of students who have taken classes from both ‘Ivana Teach’ and ‘Linda Davis’. Q4) Retrieve the snum and sname of students who have taken all classes taught by ‘Linda Davis’.
You will use PostgreSQL to execute queries on a sample dataset that consists of four tables conforming to the schema in Exercise 2. Both the dataset and instructions for connecting to the PostgreSQL server are available on the assignment web page. Please take the following steps to complete this exercise. Step 1: Place the dataset in an appropriate place in your home directory on the edlab machines. Step 2: Connect to the PostgreSQL server. Step 3: Inside PostgreSQL, change your work directory to where your dataset is placed and load the dataset into corresponding tables. E.g. yanlei=> \cd ‘path-of-dataset’ yanlei=> \copy student FROM student.txt with delimiter as ',' yanlei=> \copy faculty FROM faculty.txt with delimiter as ',' yanlei=> \copy class FROM class.txt with delimiter as ',' yanlei=> \copy enrolled FROM enrolled.txt with delimiter as ',' You can use a query to check the content of each table. E.g., yanlei=> select * from student; Step 4: Now you are ready to submit SQL queries to retrieve the required information. Submission : Please create a directory ‘hw1’ under your home directory on the edlab machines. For each query below, store in the ‘hw1’ directory a valid SQL query, named “Q1.sql”, “Q2.sql”, …, and “Q6.sql”.
Write SQL expressions for each of the following queries and execute them: Q1) Retrieve the snum of students who have taken two different classes. Please only return distinct values of snum. Q2) Retrieve the snum and sname of students who have taken a class from ‘Ivana Teach’ or ‘Linda Davis’. Q3) Retrieve the snum and sname of students who have taken classes from both ‘Ivana Teach’ and ‘Linda Davis’. Q4) Retrieve the snum and sname of students who have taken all classes taught by ‘Linda Davis’. Q5) Find the age of the youngest student who has taken ‘Database Systems’. Q6) Find the name and age of the youngest student who has taken ‘Database Systems’. (Hint: For this query, you may consider using a derived table; if it is not supported by a particular DBMS, then create a view.)
Can the following queries be expressed using conjunctive queries? If your answer is yes, write the conjunctive queries. If your answer is no, explain why. (a) find students who have taken ‘Database Systems’ but not ‘Operating Systems’ (b) find the age of the youngest student who has taken ‘Database Systems’
Joe King is designing a database for his election tracking website, JoeVotes.com. JoeVotes is designed to track information about many elections and many candidates simultaneously, and to provide information about the positions of the candidates on major issues. Joe decides he needs to store the following information: