Replicate a table every time another one is updated

0

I have two tables. Tabla A and Tabla B and I need you to just insert something in Tabla A is copied identically in Tabla B .

The fields in both tables are: id , nombre and posicion

Example:

Tabla A

id  nombre  posicion
1   carlos     1
2   luis       2

From PHP, I need to ask if there is any new data in Tabla A that needs to be copied in Tabla B , and obviously so.

    
asked by Ivan Diaz Perez 12.04.2017 в 17:53
source

1 answer

1

You can create a trigger in your database so that for each INSERT in the tableA take the inserted data and insert it in tableB:

DELIMITER #
CREATE
    TRIGGER insert_into_tablaA AFTER INSERT ON tablaA
FOR EACH ROW BEGIN
    INSERT INTO tablaB (nombre, posicion) VALUES (new.nombre, new.posicion)
END#;
    
answered by 12.04.2017 в 18:04