For all written homework assignments you are welcome, and encouraged, to work in small groups (2 or 3 students) either trying to solve the problems together or trying to verify each other's solutions prior to submitting them. If you solve the problems as a group, you should submit your own write-up of the assignment and list the other students with whom you worked.
The relations for this assignment have the following schema (the primary key is in italics):
Student(Snum, Name, Major, Level, Age)
Class(Name, Time, Room, Fid)
Enrolled(Snum, ClassName)
Faculty(Fid, Name, Dept)
To use Postgress's SQL interface:
% psql -U your_user_name -h milk cs44db # I'd do the following: % psql -U newhall -h milk cs44db Welcome to psql 7.4.17, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit
cs44db=> SELECT * FROM Student; cs44db=> SELECT * FROM Class; cs44db=> SELECT * FROM Enrolled; cs44db=> SELECT * FROM Faculty;
or I think it is just as easy to use the help feature:
# to see syntax for the SELECT SQL command: cs44db=> \h select # to see list all SQL commands: cs44db=> \h
cs44db=> \q
Write the following queries in SQL and run them on the cs44db on Postgress.
You can capture Postgress's output (all terminal input and output)
by first running
script, then running psql ...
. After running all your queries
and exiting psql, type exit to quit script. You now have a file named
typescript that you then clean up with dos2unix
and edit with
comments indicating which query corresponds to each chunk of output.
Queries 1, 3, 6 and 9 should also be written in Relational Algebra. If a query cannot be expressed in one or both of the query languages explain why it cannot.
At the beginning of class, hand in a printout of your script file of Postgress's output for the SQL queries and your written answers to the relational algebra queries. Clean-up the typescript file and add comments indicating which query is which in the ouput:
################################################################ # Query 1: Find the names of all CS Majors (Major = 'CS') who # are enrolled in the course 'Math06': # cs44db=> SELECT name ...