JLudt
JLudt

Reputation: 9

mysql trigger inserting duplicate rows

This is the first time I'm having to create a trigger in mysql. I'm trying to update a small log table (4 columns) one of which is a URL. I have it working except I can't figure out how to prevent it from inserting 2 rows when the trigger fires. I cannot create a unique index on the url row because of max key length. Any suggestions on other means? I've tried insert via select statements and using ON DUPLICATE KEY with no success.

CREATE DEFINER=`dbuser`@`%` TRIGGER `upd_url_prod` AFTER UPDATE ON  `products` 
FOR EACH ROW BEGIN
INSERT INTO my_changes (ext_id,url,changetime)
VALUES (NEW.external_id,NEW.detail_url,NOW());

END

Upvotes: 0

Views: 1004

Answers (1)

Madhur Sharma
Madhur Sharma

Reputation: 142

I think you need to check your update query on that trigger fires. Perhaps that query is firing two time and trigger is firing. check your script where update query is running and log that query.

Upvotes: 0

Related Questions