Sie sind auf Seite 1von 5

Tutorial 4 REPORT

CMT221 DATABASE ORGANIZATION AND DESIGN


KHAIRUL AZIM BIN MAHAMAD

127133

1. The management would like to have a list of books located at both locations
without the duplicates. Attributes which have to be shown in the list are ISBN,
title, category and cost. How many records will be in the list?
There are 11 records in the list.
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:
SELECT COUNT(ISBN) AS TOTAL FROM
(
SELECT ISBN, TITLE, CATEGORY, COST FROM BOOKS_IN_KL
UNION
SELECT ISBN, TITLE, CATEGORY, COST FROM BOOKS_IN_PEN
)
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.
SELECT MAX(COST) AS MAX_COST,
MIN(COST) AS MIN_COST,
ROUND(AVG(COST),4) AS AVD_COST,
ROUND(VARIANCE(COST),4) AS VARIANCE_COST,
ROUND(STDDEV(COST),4) AS STDDEC_COST
FROM
(
SELECT ISBN, COST FROM BOOKS_IN_KL
UNION
SELECT ISBN, COST FROM BOOKS_IN_PEN
)
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.
SELECT * FROM BOOKS_IN_KL
INTERSECT
SELECT * FROM BOOKS_IN_PEN
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.
SELECT * FROM BOOKS_IN_KL
MINUS
SELECT * FROM BOOKS_IN_PEN
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.

SELECT * FROM BOOKS_IN_PEN


MINUS
SELECT * FROM BOOKS_IN_KL
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.
CREATE OR REPLACE TRIGGER TRG_AUTO_COMPUTE_RET_PRICE
AFTER INSERT OR UPDATE OF COST ON BOOKS_IN_KL
BEGIN
UPDATE BOOK_IN_KL
SET RET_PRICE = 1.05 * COST;
END;

8. How many rows will be created when the following SQL command is
executed?
SELECT * FROM JOB CROSS JOIN EMPLOYEE;
198 records will be in the list.
9.

198 records will be in the list.(true)

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;

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;

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;

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;

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
SELECT JOB_CODE, JOB_DESCRIPTION, JOB_CHG_HOUR
FROM JOB
WHERE JOB_CHG_HOUR < (SELECT AVG(JOB_CHG_HOUR) FROM JOB)

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.
SELECT UPPER (EMP_LNAME) AS L_NAME , LENGTH (EMP_LNAME) AS
LNAME_SIZE , LOWER (EMP_FNAME) AS F_NAME , LENGTH (EMP_FNAME) AS
FNAME_SIZE , SUBSTR(EMP_FNAME, 1, 3) AS FNAME_PREFIX FROM
EMPLOYEE;

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. Code:
CREATE OR REPLACE PROCEDURE INCREASE_JOB_CHG_HOUR
AS BEGIN
UPDATE JOB
SET JOB_CHG_HOUR = 1.1 + JOB_CHG_HOUR
WHERE JOB_CODE = '500' OR JOB_CODE = '501' OR JOB_CODE = '502';
END;

BEGIN
INCREASE_JOB_CHG_HOUR;
END;