I am using the BEFORE INSERT event trigger using stored procedure in MySQL to update the new row once it gets inserted. I am fetching data from different sources.
The problem is when the multiple rows get inserted simultaneously, it updates the same value in both the irrelevant rows.
Please find the following trigger code for the reference.
BEGIN
DECLARE tmpId INT;
SELECT AUTO_INCREMENT INTO tmpId FROM `information_schema`.`tables` WHERE `table_schema` = 'demo_db' and `table_name` = 'test_users';
IF (NEW.parent_id IS NULL) THEN
SET NEW.parent_id = tmpId;
END IF;
END
Can any please help?