Excuse me, I am not an expert in MySql and I would like to know if it is possible to add data from one table (Results) to another table (Data) in the same DB automatically without php or another language only with pure MySql queries.
The "Results" table has several columns which I care about the "ID" and I just want to grab it and put it in the fields of the "Data" table in the "ID_data" column I am not sure how to make that insertion in the TRIGGER selecting the columns.
CREATE TRIGGER traspaso
AFTER INSERT
ON resultados FOR EACH ROW datos
INSERT INTO ID_datos
Data Table
If you want to insert the new
ID
from tableresultados
intoID_datos
, it would be like this:In the
TRIGGER
the key isNEW.
andOLD.
, which are used to refer to the new or old values, depending on the nature of the event that occurred. Here we useNEW
because, if aINSERT
(the type ofTRIGGER
isAFTER INSERT
) occurred, it is understood that there will be a new row with the new data inserted.