Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

academy.oracle.

com

Database Programming with SQL


19-1: Testing
Practice Activities

Try It / Solve It
1. Design and carry out tests to check the following:

a. The business rule that requires that employees have a job_id


b. The business rule that requires that the end date of an employment is after a start date
in the job history table.
c. The business rule that states that departments can be closed down with employees in
that department (resulting in the department_id becoming unknown).
d. The minimum salary of an employee is 1000.

Solution:
Test Num-

Expected Result/
Test De-
scription

Input Action
Output Discrepancy
Date
ber

1 a INSERT INTO employees (em- cannot in- cannot insert NULL None
ployee_id, first_name, sert NULL into JOB_ID
last_name, email, phone_num- into
ber, hire_date, job_id, salary, JOB_ID
commission_pct, manager_id,
department_id)
VALUES (300, 'Fred', 'Smith',
'a@b.com', 123456, '01-Jan-
2006',
NULL,2000,NULL,100,90) ;
2 b INSERT INTO job_history (em- Check Check constraint vi- None
ployee_id, start_date, constraint olated
end_date, job_id, depart- violated
ment_id)
VALUES (400, '01-Jan-2006',
'01 DEC 2005','IT_PROG',60) ;
3 c DELETE departments 1 row de- integrity constraint Alter refer-
WHERE department_id =10 ; leted violated - child rec- ential integ-
ord found rity con-
straint
Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.
2

4 d INSERT INTO employees (em- Check 1 row inserted Alter check


ployee_id, first_name, constraint constraint
last_name, email, phone_num- violated
ber, hire_date, job_id, salary,
commission_pct, manager_id,
department_id)
VALUES (300, 'Fred', 'Smith',
'a@b.com', 123456, '01-Jan-
2006','IT_PROG',999,NULL,
100, 90) ;

2. If one of the above tests fails, write out the SQL statement(s) that would be needed to
correct the test. With the permission of your teacher, implement the change and then
rerun the test with the same input and confirm that it works.

Solution:

c. ALTER TABLE employees


DROP CONSTRAINT emp_dept_fk ;

ALTER TABLE employees


ADD CONSTRAINT emp_dept_fk FOREIGN KEY (department_id)
REFERENCES departments(department_id) ON DELETE SET NULL ;

d. ALTER TABLE employees


DROP CONSTRAINT emp_salary_min ;

ALTER TABLE employees


ADD CONSTRAINT emp_salary_min CHECK (salary >= 1000) ;

Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.

You might also like