cannot update the table

23 Views Asked by At
CREATE TRIGGER `update_account_status` BEFORE UPDATE ON `users`
 FOR EACH ROW BEGIN
    DECLARE failed_attempts INT;
    -- Get the number of failed login attempts for the user
    SELECT login INTO failed_attempts
    FROM users
    WHERE u_id = NEW.u_id;
    -- Check if the failed attempts are greater than or equal to 3
    IF failed_attempts >= 3 THEN
        -- Update the account_status to 'Locked'
        UPDATE users
        SET account_status = 'locked'
        WHERE u_id = NEW.u_id;
    END IF;
END

I tried upadting the user table like this

UPDATE users SET login = login + 1 WHERE username = 'rohini'

And am getting this error

#1442 - Can't update table 'users' in stored function/trigger because it is already used by statement which invoked this stored function/trigger

0

There are 0 best solutions below