users(id,company,name)
This is my schema for the table. How should i write a trigger to check for the duplicates before inserting the new row. I need to check the incoming data is not duplicated with the incoming record. if the incoming record is existing that record should not be inserted to the table. If its not duplicating that record hould be inserted!
Below is the trigger i tried but it gives an error at the 'last end' line
DELIMITER $$
CREATE TRIGGER userDuplicate
BEFORE INSERT ON `users` FOR EACH ROW
BEGIN
DECLARE recordId VARCHAR(999);
SET recordId = (SELECT id FROM users WHERE company= NEW.companyAND name = NEW.name);
IF recordId IS NOT NULL
THEN
INSERT INTO users (company,name) VALUES (NEW.name,NEW.company);
END IF;
END;
$$ DELIMITER;