Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

h.w2/ write the trigger that check the new salary of the employee is greater than the manger of employee. if yes than more using exception,if

h.w2/ write the trigger that check the new salary of the employee is greater than the manger of employee. if yes than more using exception,if not than execute the query and add this update to log table.?

CREATE TRIGGER salary_trigger BEFORE UPDATE ON public.employee FOR EACH ROW EXECUTE PROCEDURE public.change_salary(); CREATE OR REPLACE FUNCTION public.change_salary() RETURNS trigger LANGUAGE 'plpgsql' AS $BODY$ BEGIN IF NEW.salary > 80000 THEN RAISE EXCEPTION 'HIGH SALARY IS NOT VALID!'; END IF; IF NEW.salary <> OLD.salary THEN INSERT INTO salary_logs(emp_ssn, old_salary, new_salary, changed_time) VALUES(OLD.ssn,OLD.salary,NEW.salary,now()); END IF; RETURN NEW; END; $BODY$; select * from employee select * from salary_logs /* select * from extra_hours_for_emp */ /* select fname, lname, salary from employee where ssn in (select essn as total_hours from works_on group by essn having sum(hours) > 35) */ /* WITH RECURSIVE under_member AS ( SELECT id, member_name, p_id FROM org_structure WHERE id = 2 UNION SELECT o.id, o.member_name, o.p_id FROM org_structure o INNER JOIN under_member u ON u.id = o.p_id ) SELECT * FROM under_member; */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What does procurement mean?

Answered: 1 week ago