0
After inserting in "banco1.customers" I want to insert the same content in "banco2.Customers", but error appears.
I saw that Mysql does not allow two operations in the same table, but they are different banks.
This Rigger was working a while back, but now it returns this code, which I may have done wrong?
Code:
INSERT INTO banco1.Clientes VALUES (42,'mariana', '1998-05-08', '48381856' '4539-6', 'ananana', 'oqe?', '162', 'sasnaush', 'qsjqijqiwj',
'SP', '13720000');
DELIMITER $$
CREATE TRIGGER insereBanco1 AFTER INSERT
ON banco1.Clientes FOR EACH ROW
/* insercao */
BEGIN
INSERT INTO banco2.Clientes (id, nome, dat_nascimento, cpf, rg, endereco, numero, bairro, cidade, estado, cep)
SELECT id, nome, dat_nascimento, cpf, rg, endereco, numero, bairro, cidade, estado, cep FROM banco1.Clientes WHERE
id NOT IN (SELECT id FROM banco2.Clientes);
END;
$$
ERROR:
15:27:13 INSERT INTO banco1.Clientes VALUES (42,'mariana', '1998-05-08', '48381856' '4539-6', 'ananana', 'oqe?', '162', 'sasnaush', 'qsjqijqiwj', 'SP', '13720000') Error Code: 1442. Can't update table 'clientes' in stored function/trigger because it is already used by statement which invoked this stored function/trigger. 0.000 sec
Enter the error description.
– Sorack
ready! I entered the error
– Weslley Fillipe
You’re making a
SELECT
on the line where you have not yet completed the update operation. To get the values of this line use the keywordsOLD
andNEW
– Augusto Vasques
thanks for the reply Augusto! I will study the question of old and new, because I have not learned yet.
– Weslley Fillipe