Last active
November 16, 2023 02:34
-
-
Save rithask/af962bd50c7d7147bb722da8f2045ef3 to your computer and use it in GitHub Desktop.
KTU DBMS Lab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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