0% found this document useful (0 votes)
43 views5 pages

Tut 04

This document provides instructions and questions for a database tutorial. It describes two tables containing book information and job/employee data. Students are asked to write SQL queries using relational operators to retrieve, manipulate and analyze data between the tables. Examples of desired outputs are provided. Triggers and stored procedures are also introduced.

Uploaded by

Muhd Firdaus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views5 pages

Tut 04

This document provides instructions and questions for a database tutorial. It describes two tables containing book information and job/employee data. Students are asked to write SQL queries using relational operators to retrieve, manipulate and analyze data between the tables. Examples of desired outputs are provided. Triggers and stored procedures are also introduced.

Uploaded by

Muhd Firdaus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

School of Computer Sciences, USM, Penang

CMT221/CMM222: Database Organization and Design

Tutorial 04 – Advanced SQL

Instruction: In order to complete this tutorial, kindly execute the script and import the data from the
respective csv files. The script and the csv files can be obtained via eLearn@USM.

Two tables BOOKS_IN_KL and BOOKS_IN_PEN are created in a database to store book information
at two difference locations, one in Kuala Lumpur and one in Penang. Based on Figure 1 and Figure 2,
answer the following questions (Questions 1 – 7). You must use the relational set operators (e.g.
UNION, INTERSECT or MINUS) in your SQL commands, wherever applicable.

Figure 1: BOOKS_IN_KL table.

Figure 2: BOOKS_IN_PEN table.

Page | 1 CMT221/CMM222: Database Organization and Design (Tutorial 04)


LSY, TJS
Question 1:
The management would like to have a list of books located at both locations without the duplicates.
Attributes to be shown in the list are ISBN, title, category and cost. Write the SQL statement. How many
records will be in the list?

Question 2:
The management would like to know the total number of books located at both locations (duplicates
are allowed). Your SQL statement must produce a display as follows:

Question 3:
The management would like to know the statistical information of cost price of all the distinct books
located at both locations. These include maximum, minimum, average, standard deviation and variance
of the cost price. Your SQL statement must produce a display as follows. Please take note that the
values for average, standard deviation and variance must be rounded to 4 decimal places.

Question 4:
The management would like to get a list which shows the common books in both locations. All columns
must be included in the display list.

Question 5:
The management would like to get a list which shows the books at Kuala Lumpur branch but not
available at the Penang branch. All columns must be included in the display list.

Question 6:
The management would like to get a list which shows the books at Penang branch but not available at
the Kuala Lumpur branch. All columns must be included in the display list.

Question 7:
Create a trigger which does the following: whenever a record in the BOOKS_IN_KL table is updated or
a new record is inserted, the RET_PRICE will be auto computed as 5% more than the cost price. For
instance, a book with cost price of $10.00 is inserted; the RET_PRICE of that book would be $10.50.

Page | 2 CMT221/CMM222: Database Organization and Design (Tutorial 04)


LSY, TJS
Two tables JOB and EMPLOYEE are created as shown in Figure 3 and Figure 4. These two
relationships are lined with 1:M relationship where one job can be handled by many employees. Based
on Figure 3 and Figure 4, answer the following question (Questions 8 – 16).

Figure 3: JOB table.

Figure 4: EMPLOYEE table.

Page | 3 CMT221/CMM222: Database Organization and Design (Tutorial 04)


LSY, TJS
Question8:
How many rows will be listed when the following SQL command is executed?
SELECT * FROM JOB CROSS JOIN EMPLOYEE;

Question 9:
By running the following SQL command,
SELECT * FROM JOB, EMPLOYEE;
similar results as of what have been produced by the SQL command in Question 8 can be generated.
[TRUE/FALSE]

Question 10:
Produce the output based on the following SQL command.
SELECT JOB_CODE, JOB_DESCRIPTION, EMP_LNAME
FROM JOB NATURAL JOIN EMPLOYEE
ORDER BY EMP_LNAME;

Question 11:
Produce the output based on the following SQL command.
SELECT JOB_CODE, JOB_DESCRIPTION, EMP_LNAME
FROM JOB JOIN EMPLOYEE USING(JOB_CODE)
ORDER BY EMP_LNAME;

Question 12:
Produce the output based on the following SQL command.
SELECT JOB_CODE, EMP_LNAME
FROM JOB LEFT JOIN EMPLOYEE USING(JOB_CODE)
ORDER BY EMP_LNAME;

Question 13:
Produce the output based on the following SQL command.
SELECT JOB.JOB_CODE, EMP_LNAME
FROM JOB LEFT JOIN EMPLOYEE ON JOB.JOB_CODE = EMPLOYEE.JOB_CODE
ORDER BY EMP_LNAME;

Question 14:
Produce a list of jobs from the JOB table where the JOB_CHG_HOUR is lesser than the overall
average of the JOB_CHG_HOUR. The anticipated output is shown as follows:

Page | 4 CMT221/CMM222: Database Organization and Design (Tutorial 04)


LSY, TJS
Question 15:
Produce a list of employees from the EMPLOYEE table with the following display:

The first column displays the last name in all capital letters. The third column displays the first name
in all lowercase letters. The second and the fourth columns display the size of the last name and the
first name respectively. The fifth column displays the first three characters of the first name.

Question 16:
Create a stored procedure which does the following: increase the JOB_CHG_HOUR in the JOB table
to 10% of the original value for Programmer, Systems Analyst and Database Designer. Execute the
stored procedure.

~~END OF TUTORIAL 04~~

Page | 5 CMT221/CMM222: Database Organization and Design (Tutorial 04)


LSY, TJS

You might also like