I have a trigger which is working fine.
CREATE TRIGGER crm_listings__au
AFTER UPDATE
ON crm_listings FOR EACH ROW
INSERT INTO crm_listings_versions
SELECT
'update', NULL, NOW(), NULL, d.*
FROM
crm_listings AS d
WHERE
d.id = NEW.id;
Now I want to keep track of the field column name also. I am thinking I could not do in above query so I changed to below trigger
CREATE TRIGGER crm_listings__au
BEFORE UPDATE
ON crm_listings
FOR EACH ROW
BEGIN
IF OLD.type != NEW.type
THEN
INSERT INTO crm_listings_versions
SELECT
'update', NULL, NOW(), 'type', d.*
FROM
crm_listings AS d
WHERE
d.id = NEW.id;
END IF;
IF OLD.price != NEW.price
THEN
INSERT INTO crm_listings_versions
SELECT
'update', NULL, NOW(), 'price', d.*
FROM
crm_listings AS d
WHERE
d.id = NEW.id;
END IF;
END;
$$
When I run this code, I get this error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 10
UPDATE:
I followed this post on stackoverflow