11.09.2018 Views

Aprender a desarrollar un sitio Web con PHP y MySQL

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

En lenguaje SQL:<br />

CREATE TRIGGER `COMPROBAR_EDAD` BEFORE INSERT ON `Persona`<br />

FOR EACH ROW BEGIN<br />

IF NEW.edad > 100 THEN<br />

SET NEW.edad = 100;<br />

END IF;<br />

END<br />

Si inserta <strong>un</strong>a persona <strong>con</strong> <strong>un</strong>a edad superior a 100, se le asignará 100 a su edad.<br />

Siempre es posible modificar la edad y asignar <strong>un</strong> valor superior a 100 porque el trigger está<br />

asociado al evento INSERT y no al evento UPDATE. Además no es posible tener dos triggers<br />

asociados al mismo evento y la misma acción sobre la misma tabla.<br />

En<strong>con</strong>trará más información en el<br />

enlace:http://dev.mysql.com/doc/refman/5.0/es/triggers.html<br />

www.FreeLibros.me

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!