You are on page 1of 3

CC4057 Introduction to Information

Systems
Lab work – week 4
1. Create a database named tech_academy.
2. Using the dump file tech_academy.sql load the tables and data into the
database tech_academy.
3. The following tables are already present in the database

instructors
instructorID INT PRIMARY KEY,AUTO_INCREMENT
Fname VARCHAR(50)
Lname VARCHAR(50)
Designation VARCHAR(50)

courses
courseID INT PRIMARY KEY, AUTO_INCREMENT
Name VARCHAR(50)
startDate DATE
endDate DATE
instructor INT FOREIGN KEY
price INT
*The foreign key instructor references to the instructorID column in the
instructors table

students
studentID INT PRIMARY KEY, AUTO_INCREMENT
Fname VARCHAR(50)
Lname VARCHAR(50)
dateJoined DATE
address VARCHAR(50)

4. Create a table named enrollments with the following structure


enrollmentID INT PRIMARY KEY,AUTO_INCREMENT
course INT FOREIGN KEY
student INT FOREIGN KEY
paid VARCHAR(5)
*The foreign key course references to the courseID column in the courses
table, and the foreign key student references to the studentID column in
the students table

5. Insert the following data into the enrollments table


enrollmentID course student paid
1 1 1 yes
2 1 2 no
3 1 3 yes
4 2 4 yes
5 2 5 yes
6 2 6 yes
7 3 1 no
8 3 2 yes
9 3 7 no
10 4 4 yes
11 4 3 yes
12 4 8 no
13 5 1 yes
14 5 2 no
15 5 4 yes
16 6 7 no
17 6 8 yes
18 6 4 no

6. Write SQL statements for doing the following:


a. List the first name, last name and the address of the students sorted
according to their addresses.
b. List the first name, last name and designation of the instructors
sorted according to their last names in descending order.
c. List the details of the most expensive course.
d. Show all the unique addresses of the students.
e. Show the average price of the courses offered.
f. Show all the details of the students who joined in 2016.
g. Show the first names and address of the students who are from
London.
h. Show the details of the students whose first names begin with “A” or
“J”.
i. Show the details of the instructors whose first names contain the
letter “d” inside them.
j. Show the details of the courses whose price range is between 200
and 400.
k. Show the name, startdate and price of the courses which are about
to start in april or may.
l. List the courses and the number of students enrolled in them from
the enrollments table.
m. List the students and the number of courses they have enrolled in
from the enrollments table.
n. List the instructors and the number of courses they teach from the
courses table.
o. Join the tables courses and instructors using a suitable column.
p. Join the tables enrollments and students using a suitable column.
q. Join the tables enrollments and courses using a suitable column.

7. Backup the database creating a dump file named tech_academy2.sql

You might also like