MYSQL ERROR 1442, how to resolve?

Asked

Viewed 322 times

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
  • 1

    Enter the error description.

  • ready! I entered the error

  • 1

    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 keywords OLD and NEW

  • thanks for the reply Augusto! I will study the question of old and new, because I have not learned yet.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.