Comp 468 – Database Design – Dordal – Fall 2003 – Due: Dec 1, 2003

 

This assignment will use a database containing data about a university. The relations are in a Microsoft Access 2000 database on my web page. You don’t have to use Access (MS Access SQL is notoriously nonstandard); text files containing the data in more-or-less loadable format are also available on my web page.

 

The schema of the database is provided below (keys are in bold, field types are omitted):

 

·        student(sid, sname, sex, age, year, gpa)

·        dept(dname, numphds)

·        prof(pname, dname)

·        course(cno, cname, dname)

·        major(dname, sid)

·        section(dname, cno, sectno, pname)

·        enroll(sid, grade, dname, cno, sectno)

 

Before you start writing SQL, it is a good idea to take a look at the database and familiarize yourself with its contents. I’ve provided one query, given the name doublemajors in Access, that lists those with more than one major. To see this query, right-click on it when the database opens and select design view. You may or may not also need to select SQL View from the View menu on the main menu bar. If you get a table of data, it means you ran the query rather than viewed it; Access tends to assume that running the query is what you really want. Here is the query:

 

SELECT       s.sname, s.sid, m.dname, s.gpa

FROM          student AS s, major AS m

WHERE        s.sid = m.sid and exists (

                                       SELECT    m1.sid

                                       FROM       major m1

                                       WHERE     m.sid = m1.sid and m.dname <> m1.dname

                     )

ORDER BY s.sid;

 

Write SQL queries that answer the questions below (one query per question) and run them on the SQL system of your choice. A Microsoft ACCESS database is provided; it has an embedded SQL interpreter though as indicated above it can be a little hard to find. The query answers must not contain duplicates, but you should use the SQL keyword distinct only when necessary.

 

The SQL interpreter in ACCESS is not quite standard. If the query you write is not accepted by ACCESS (usually it gives you some strange errors), try different ways until you get one that works with ACCESS. For this assignment, creation of temporary tables is strongly discouraged, i.e., for each question you have to write exactly one SQL statement to get full credit.

 

Queries

 

Write the following SQL queries:

 

1.      Print the names of professors who work in departments that have fewer than 50 PhD students.

2.      Print the name(s) of student(s) with the lowest gpa.

3.      For each Computer Sciences class, print the cno, sectno, and the average gpa of the students enrolled in the class.

4.      Print the course names, course numbers and section numbers of all sections with less than six students enrolled in them.

5.      Print the name(s) and sid(s) of the student(s) enrolled in the most classes.

6.      Print the names of departments that have one or more majors who are under 18 years old.

7.      Print the names and majors of students who are taking one of the College Geometry courses. (Hint: You'll need to use the "like" predicate and the string matching character in your query.)

8.      For those departments that have no majors taking a College Geometry course, print the department name and the number of PhD students in the department.

9.      Print the names of students who are taking both a Computer Sciences course and a Mathematics course.

10.  Print the age difference between the oldest and youngest Computer Sciences major(s).

11.  For each department that has one or more majors with a GPA under 1.0, print the name of the department and the average GPA of its majors.

12.  Print the ids, names, and GPAs of the students who are currently taking all of the Civil Engineering courses.

Assignment Submission

 

You need to turn in the twelve queries in runnable form. If you don’t use Access, the preferred form is in a text file, with the queries separated by a couple blank lines each (and hopefully with a comment before each one). If you do use Access, you are encouraged to turn in the entire database with the queries created in it. Make sure you don’t change the data itself.