Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
557 B
2
Indexable
Never
CREATE TABLE student (
    regno INT PRIMARY KEY,
    name VARCHAR(50),
    sub1 INT,
    sub2 INT,
    sub3 INT,
    sub4 INT,
    sub5 INT,
    total_mark INT,
    avg_mark FLOAT
);

DELIMITER //
CREATE TRIGGER calculate_marks
BEFORE INSERT ON student
FOR EACH ROW
BEGIN
    DECLARE total_marks INT;
    DECLARE average_mark FLOAT;
    
    SET total_marks = NEW.sub1 + NEW.sub2 + NEW.sub3 + NEW.sub4 + NEW.sub5;
    SET average_mark = total_marks / 5.0;
    
    SET NEW.total_mark = total_marks;
    SET NEW.avg_mark = average_mark;
END;
//
DELIMITER ;
Leave a Comment