0% found this document useful (0 votes)
13 views1 page

Trigger Docentes

Uploaded by

Maria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Trigger Docentes

Uploaded by

Maria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

create database ejemplotrigger;

use ejemplotrigger;
CREATE TABLE Docentes (
ceduladocente bigint PRIMARY KEY,
nombresdocente VARCHAR(30) NOT NULL,
apellidosdocente VARCHAR(30) NOT NULL,
emaildocente VARCHAR(30) NOT NULL
);

use ejemplotrigger;
CREATE TABLE logs (
id int(11) AUTO_INCREMENT PRIMARY KEY ,
docente_id int(11) NOT NULL,
action varchar(20) NOT NULL,
cdate date NOT NULL
);

***** creación de los trigger ****


*** al insertar docentes
use ejemplotrigger;
DELIMITER $$
CREATE TRIGGER insertlog AFTER INSERT ON Docentes FOR EACH ROW insert into logs
VALUES(null,NEW.ceduladocente,'Insertded',NOW())
$$
DELIMITER ;

*** actualizar docentes


use ejemplotrigger;
DELIMITER $$
CREATE TRIGGER actualizalog AFTER UPDATE ON Docentes FOR EACH ROW
BEGIN
insert into logs values(null,NEW.ceduladocente, 'updated',now());
END
$$
DELIMITER ;

*** eliminar docentes


use ejemplotrigger;
DELIMITER $$
CREATE TRIGGER eliminalog BEFORE DELETE ON Docentes FOR EACH ROW
BEGIN
insert into logs values(null,OLD.ceduladocente, 'delete',now());
END
$$
DELIMITER ;

You might also like