Skip to content

Instantly share code, notes, and snippets.

@rithask
Last active November 16, 2023 02:34
Show Gist options
  • Save rithask/af962bd50c7d7147bb722da8f2045ef3 to your computer and use it in GitHub Desktop.
Save rithask/af962bd50c7d7147bb722da8f2045ef3 to your computer and use it in GitHub Desktop.
KTU DBMS Lab
/*
AIM:
Given Student Report Database, in which student marks assessment is recorded. In such schema, create a trigger so that the total and average of specified marks is automatically inserted whenever a record is inserted.
Student
Sid name Subj1 Subj2 Subj3 Total Avg
*/
DELIMITER //
CREATE TRIGGER CalculateTotalAndAverage
BEFORE INSERT ON Student
FOR EACH ROW
BEGIN
-- Calculate the Total
SET NEW.Total = NEW.Subj1 + NEW.Subj2 + NEW.Subj3;
-- Calculate the Average
SET NEW.Avg = (NEW.Subj1 + NEW.Subj2 + NEW.Subj3) / 3;
END;
//
DELIMITER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment