0

Is this possible? Before a row is inserted into tableA, I need to delete any rows in tableA containing duplicate data.The trigger below does not generate an error but doesn't work either.

CREATE TRIGGER remove_old_user
BEFORE INSERT ON userStatus
FOR EACH ROW
DELETE FROM userStatus WHERE username = NEW.username

Any ideas?

1 Answer 1

3

Is it essential that the previous record be deleted, rather than updated to match the new info? Sounds like INSERT ... ON DUPLICATE KEY UPDATE would meet most of your needs. More info in the MySQL manual.

(I'm assuming based on the question that the field is unique, and can be part of the primary key)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.