Question: Consider the following PL / SQL function and trigger created for security reasons. CREATE OR REPLACE FUNCTION prevent _ user _ deletion ( ) RETURNS
Consider the following PLSQL function and trigger created for security reasons.
CREATE OR REPLACE FUNCTION preventuserdeletion
RETURNS TRIGGER AS $$
BEGIN
IF OLD.userrole 'admin' THEN
RAISE EXCEPTION 'Cannot delete an admin user.;
END IF;
RETURN OLD;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER checkuserdeletion
BEFORE DELETE ON users
FOR EACH ROW EXECUTE FUNCTION preventuserdeletion;
What can be said in regards to the checkuserdeletion trigger and the preventuserdeletion function?
The function contents could have been put directly in the trigger but this is a "cleaner" code
This trigger does not work as the function is not set up properly
A trigger must always be implemented with a function
A function can only be used with a trigger
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
