I have a XML file which contains 200k records. I have to insert or update the records in the database. My database structure is as followed:
+----+------+-------+-----+-----+------------+
| Id | name | stock | sku | ean | updated_by |
+----+------+-------+-----+-----+------------+
For inserting the records i'm using Doctrine. But it takes to long before all records are inserted or updated. Therefore I want to create a stored procedure.
I tried the following stored procedure but it's not working.
delimiter $$
create trigger insert
before insert on Product
for each row
begin
IF(exists(select 1 From Product WHERE sku = new.sku))
THEN
BEGIN
UPDATE Product SET stock = new.stock WHERE sku = sku;
END;
END IF;
end$$
delimiter
Error:
General error: 1442 Can't update table 'Product' in stored function/trigger because it is already used by statement which invoked this stored function/trigger
Update: