The document creates a database and table for students. It then creates two triggers for the student table. The before insert trigger checks that any inserted grade is between 0 and 10. The before update trigger performs the same check for any updated grades.
The document creates a database and table for students. It then creates two triggers for the student table. The before insert trigger checks that any inserted grade is between 0 and 10. The before update trigger performs the same check for any updated grades.
The document creates a database and table for students. It then creates two triggers for the student table. The before insert trigger checks that any inserted grade is between 0 and 10. The before update trigger performs the same check for any updated grades.
CREATE TABLE IF NOT EXISTS alumnos ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, nombre VARCHAR(50), apellido1 VARCHAR(50), apellido2 VARCHAR(50), nota FLOAT );
-- Crear el trigger trigger_check_nota_before_insert
DELIMITER // CREATE TRIGGER trigger_check_nota_before_insert BEFORE INSERT ON alumnos FOR EACH ROW BEGIN IF NEW.nota < 0 THEN SET NEW.nota = 0; ELSEIF NEW.nota > 10 THEN SET NEW.nota = 10; END IF; END; //
-- Crear el trigger trigger_check_nota_before_update
DELIMITER // CREATE TRIGGER trigger_check_nota_before_update BEFORE UPDATE ON alumnos FOR EACH ROW BEGIN IF NEW.nota < 0 THEN SET NEW.nota = 0; ELSEIF NEW.nota > 10 THEN SET NEW.nota = 10; END IF; END; //