- Using either PHPMyAdmin or from the command line, create a new
database ("registration"), copy and paste the DDL and INSERT statement
for the tables from the file in the link given above, but you still have
to create the database first).
Students using the VM: Although the Company database is already
installed on the VM, the registration database is not, so you will have
to create it.
- Use SQL to define the following view: (use CREATE VIEW.
Google it if you have to, although there is an example in our lab
that demonstrates creating a view.)
Student ID
|
Student Name
|
38214
|
Letersky
|
54907
|
Altvater
|
66324
|
Aiken
|
- Because of referential integrity, before any row can be entered into
the SECTION table, the CourseID to be entered must already exist in the
COURSE table. What is the statement/clause in the DDL that
enforces this relationship?
- Write SQL (DDL) commands for the following:
a. How would you add an attribute, GPA, to
the Student table? Make sure that your data type accommodates an
appropriate GPA.
b. How would you remove the Student table? (Don't really remove
the STudent table. Just write the command so that I know that you
know how.)
c. How would you change the StudentName field from 25 characters to 40
characters?
- Write SQL commands for the following:
a. Write two different forms of the INSERT
command to add a student with a student ID of 12345 and last name Lapin
to the Student table.
b. Now write a command that will remove Lapin from the Student table.
c. Create an SQL command that will modify the name of the course ISM
4212 from "Database" to "Introduction to Relational Databases".
d. Did you get an error or a warning when you tried to do this?
Or, is there something "not right" about the course name in the
database? If so, why? How might you address this?
- Write SQL statements to answer the following questions:
a. Which faculty have an ID number that is
less that 4000? List the faculty name(s)
b. What is the name of the student whose ID is 66324?
c. What is the largest section number used in the first semester of
2008?
- Write SQL queries to answer the following questions:
(remember: no joins or subqueries!)
a. How many faculty are qualified to teach
ISM 3113? Just display the number.
b. Who are the faculty who are qualified
to teachISM 3113? Display the faculty ID number.
c. Which faculty members have qualified
to teach a course before 1995? List the faculty ID, course, and
date of qualification.
- Write SQL queries to answer the following questions: (remember:
no joins or subqueries!)
a. Which students are enrolled in
both
Database and Networking? (Hint: use SectionNo for each
class, so that you can determine the answer from the Registration table
by itself, since we are not using joins in this homework.
Similarly, display the StudentID, because that is also in the
Registration table..)
Do this without a join or subquery:
use GROUP BY and HAVING.)
- Recall that in Question 5, you changed the name of the Database
course to Introduction to Database Programming. Whatever its
current name, that's the course you're interested in. Note
that there is only one student who should be included in the query
response, which is student number 54907.
- This question is a big challenge. It would help if you list
the StudentID and the Count(*) in your Select clause. Big
hint: You're going to need the Count later. This query
is not as straightforward as you might think. It helps to
recall that a WHERE clause only looks at one row at a time.
There does not exist any single row in the table where a student is
enrolled in both DB and Networking at the same time. Clearly,
you will have to find a way to look at multiple rows at one
time. Think of what we learned that references more than one
row at a time.
b. Which instructors can teach either Syst Analysis or Syst Design, but
cannot teach both? (Again, you should reference the CourseID, which
appears in the Qualified table.)
- In our data, there are no faculty who teach only one but not the
other. So add a tuple to Faculty and to Qualified:
- For the Faculty table, insert FacultyID 1111 and FacultyName
'Someone'
- For Qualified, insert (1111,'ISM 3113', '1996-09-01')
c. Now re-execute the query, and you should have the Faculty ID for
Someone listed in the result. (You will not have the actual name
'Someone' listed, because that would require a join, which is not
required/allowed for this homework. But it should display the
FacultyID 1111.)
- Write SQL queries to answer the following questions: (remember:
no joins or subqueries!)
a. What are the courses included in the Registration table? List each
course only once. Since we are not using joins, just display the
CourseID.
b. List all Facutly in alphabetical order by FacultlyNam
c. List the students who are enrolled in each course in Semester I,
2008. Group the students by the sections in which they are
enrolled. (Hint: "Group" is an English word that may or
may not correspond to the SQL GROUP clause.)
d. How many courses of each prefix are being offered? (ISM is the only
prefix shown, but there may be others throughout the university.
A prefix is like a department name, so similar to the COMP part of
COMP353. If you really want to test this query to see if it
works, you may want to temporarily add two courses with another
3-character prefix to the database.)