Question: Consider the following PL / SQL function and trigger created for security reasons. CREATE OR REPLACE FUNCTION prevent _ user _ deletion ( ) RETURNS

Consider the following PL/SQL function and trigger created for security reasons.
CREATE OR REPLACE FUNCTION prevent_user_deletion()
RETURNS TRIGGER AS $$
BEGIN
IF OLD.user_role = 'admin' THEN
RAISE EXCEPTION 'Cannot delete an admin user.';
END IF;
RETURN OLD;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER check_user_deletion
BEFORE DELETE ON users
FOR EACH ROW EXECUTE FUNCTION prevent_user_deletion();
What can be said in regards to the check_user_deletion trigger and the prevent_user_deletion 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
 Consider the following PL/SQL function and trigger created for security reasons.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!