Docsity

Homework 3 - Database Systems – 2009 | CS 430, Assignments of Deductive Database Systems

Toggle sidebar
bg1
CS 430 Database Systems
Homework Assignment 3 - Due 02/19/2009
1. Consider the following University Database schema:
Department(dcode: string, dname: string, chair ssn: integer)
Course(dcode: string, cnum: integer, title: string, credits: integer)
Prereq(dcode: string, cnum: integer pcode: string, pnum: integer)
Class(classnum: integer, dcode: string, cnum: integer, instructor ssn: inte-
ger)
Faculty(ssn: integer, fname: string, dcode: string, rank: string)
Student(ssn: integer, sname: string, major: string, status: string)
Enrollment(classnum: integer, student ssn: integer)
Transcript(student ssn: integer, dcode: string, cnum: integer, grade: string)
The primary keys are underlined. The attribute chair ssn in Department
refers to the ssn in Faculty table. instructor ssn refers to ssn in Faculty
table and student ssn refers to ssn in Student table. classnum is a unique
id for each offering of a course. (For example, a class with classnum =
10225 may be an offering of CS 430, in which case we have a row like
<10255,CS,430,123456789 >in the Class table.) <pcode,pnum >in the
Prereq table refers to <dcode,cnum >in the Course table. An example row
in Prereq table is <CS,430,CS,314 >, which means that CS 430 needs CS
314 as a prerequiste.
Implement the following queries using mySQL.
(a) List the classes (classnum) taken by students whose names start with
’A’.
(b) List the students (ssn and name) who are currently taking exactly one
class.
(c) Give the percentage of students (among all students) who are currently
taking courses offered by CS (dcode = CS).
(d) List the faculty members (fname) who teach 2 or more classes. List
these faculty members by the number of classes they teach.
1
pf2

Partial preview of the text

Download Homework 3 - Database Systems – 2009 | CS 430 and more Assignments Deductive Database Systems in PDF only on Docsity!

CS 430 Database Systems

Homework Assignment 3 - Due 02/19/

  1. Consider the following University Database schema:

Department(dcode: string , dname: string , chair ssn: integer ) Course(dcode: string , cnum: integer , title: string , credits: integer ) Prereq(dcode: string , cnum: integer pcode: string , pnum: integer ) Class(classnum: integer , dcode: string , cnum: integer , instructor ssn: inte- ger ) Faculty(ssn: integer , fname: string , dcode: string , rank: string ) Student(ssn: integer , sname: string , major: string , status: string ) Enrollment(classnum: integer , student ssn: integer ) Transcript(student ssn: integer , dcode: string , cnum: integer , grade: string ) The primary keys are underlined. The attribute chair ssn in Department refers to the ssn in Faculty table. instructor ssn refers to ssn in Faculty table and student ssn refers to ssn in Student table. classnum is a unique id for each offering of a course. (For example, a class with classnum = 10225 may be an offering of CS 430, in which case we have a row like < 10255 , CS , 430 , 123456789 > in the Class table.) < pcode , pnum > in the Prereq table refers to < dcode , cnum > in the Course table. An example row in Prereq table is < CS , 430 , CS , 314 >, which means that CS 430 needs CS 314 as a prerequiste. Implement the following queries using mySQL.

(a) List the classes ( classnum ) taken by students whose names start with ’A’. (b) List the students ( ssn and name ) who are currently taking exactly one class. (c) Give the percentage of students (among all students) who are currently taking courses offered by CS ( dcode = CS). (d) List the faculty members ( fname ) who teach 2 or more classes. List these faculty members by the number of classes they teach.

(e) List the students ( ssn and sname ) along with the number of classes they are taking. If a student is not taking any class, the student should also be listed (with 0 as the number of classes he/she is taking). The list should be ordered by the number of classes (in an ascending order), and in case of a tie, by the ssn of the students. (f) List the faculty members ( fname ) who teach at least twice as many classes as Professor Smith ( fname = Smith) is teaching. (Note that if Professor Smith is not teaching anything, then any professor who teaches at least one class will satisfy the above query.) (g) List the courses ( dcode and cnum ) that require the least number of prerequiste courses among those which do require some prerequisite courses (that is, if a course does not require any prerequisite, do not count it). (h) Find the number of departments which do not have a chairman ( chair ssn is null). (i) List only the students ( ssn and sname ) who satisfy the condition that the number of units the students have taken plus the number of units they are currently taking is greater than or equal to 9. (j) For each department ( dcode ), give the number of graduate students ( status = Grad) and the number of other students ( status 6 = Grad). (k) For each department ( dcode ), give the highest rank of the professors in the department along with the number of the faculty with that high- est rank. The output contains one row for each department. Assume Full > Associate > Assistant (lexicographic order is okay). Note that some department may not have professors in some ranks (example, a department may not have full or associate or assistant professors).

Please keep in mind:

  • This assignment is to be done individually. The honor code is in effect.
  • You must submit a hard copy in class and also mail the TA an electronic version of the SQL queries.
  • Assignments must be submitted before class on Thursday, February 19. No late work will be accepted except in exigent situations.
  • Your answers must be typed.