1
I am having trouble updating my stock table using a stored Procedure in MYSQL. Follows the code:
CREATE DEFINER=`root`@`localhost` PROCEDURE `atualiza_estoque`(id_produto int)
BEGIN
update estoque e inner join reposicao r on r.produto = e.produto
set e.qtd = if (e.qtd = 0, r.qtd, e.qtd+r.qtd), e.data_entrada = now()
where e.produto = id_produto and r.produto=id_produto and r.data_reposicao > e.data_entrada;
END
When calling the trial call atualiza_estoque(1);
, error message is displayed
Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Editor and Reconnect.
The funny thing is that I was able to run the trial twice before this message appeared. What was causing this error? I tried to pass the stock id as parameter, but the same message appears.
Note: I know it is possible to disable safe update, but I would like to understand what is causing this error, since Procedure worked perfectly twice before presenting the error.