Question: Q1. Create a trigger on the employees table. The trigger should skip all inserts whenever the salary of the employee to be added is less
Q1. Create a trigger on the employees table. The trigger should skip all inserts whenever the salary of the employee to be added is less than the minimum salary of a current employee. For example, if the table contains three rows (45, Jack, 40000), (34, Sam, 35000) and (12, Pat, 45000), then an insert with a salary of less than 35000 should not be done. All other inserts should be done as normal. Q1 answer: Ans): Trigger: set SERVEROUTPUT ON create or replace trigger emp_t before insert on emp for each row DECLARE min_sal number; begin select min(salary) into min_sal from emp; IF (:new.salary < min_sal) THEN raise_application_error( -20001, 'No insertion with salary less than '||min_sal||'.'); END IF; end;
Now here is the question for this post:
Q2: Create another trigger on the employees table. This time, if the salary is null, set the salary equal to the smallest salary in the employees table + 5000. In other words, if the table has the same three rows as above (question 1), then an insert of (20, Tracy, null) will insert Tracy and set their salary to 40000 (= min salary + 5000) (= 35000 + 5000).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
