I have the tablau
:
Nombre ApellidoP ApellidoM
Juan Ruiz Robles
Pedro Lopez Lopez
Luis Diaz Ruiz
and the tablelog_users
id fecha_delete Nombre
null null null
Also I have the following Trigger
:
CREATE DEFINER=`root`@`localhost` TRIGGER PRUEBA_BD_TRIGGER
BEFORE DELETE ON test.tablau
FOR EACH ROW
BEGIN
INSERT INTO test.log_users
(fecha_delete,Nombre) VALUES (now(),Nombre);
END
I remove records from the tablau
like this:
delete FROM test.tablau where Nombre = 'Luis';
The trigger does the following on the table log_users
:
id fecha_delete Nombre
1 2017-01-11 14:49:13
As you can see, it does not save the field Nombre
of the deleted row, how can I do that in the Trigger?
Use something like this:
With
OLD
indicates the old value of the column. For more information the official documentation of Trigger in MySQL :