I'm trying to build a trigger in MariaDB to follow this logic:
1. If the primary key val exists, increment the counter column
2. Else, insert the primary key into the table
Here is my prosed trigger:
delimiter //
CREATE TRIGGER volume_manager BEFORE INSERT ON individual_key_log
FOR EACH ROW
BEGIN
IF NEW.reference_key not in (
select *
From individual_key_log
where (NEW.reference_key = 'test')
) THEN -- MISSING THEN
CALL `Insert not allowed`;
END IF;
END;
//
delimiter ;
SHOW CREATE TABLE individual_key_log;would help. Which is the "counter" column? Do you want to insert or not if the key does not exist in the table? (that "insert not allowed" is confusing) – ypercubeᵀᴹ May 27 '16 at 16:17TRIGGER. – Rick James Jun 04 '16 at 21:18