Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Accesing the data from a row where trigger is assigned

I have encountered a problem when I’ve designed this trigger:

CREATE TRIGGER StudentNewAssignment BEFORE INSERT
ON classassignment FOR EACH ROW 
insert into StudentTeacherLog(studentID, teacherID, description, reason)
values((select ID from student where classID = classassignment.classID), 1, 'Test', 'da');

Basically. When trigger hits, I want to access the data from newly inserted row in classassignment and use it in a subquery which will extract data from student table related to the ‘data accesed from table where trigger hits’.
Hope I’ve made it clear. Thanks =)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

https://dev.mysql.com/doc/refman/8.0/en/create-trigger.html says:

Within the trigger body, you can refer to columns in the subject table (the table associated with the trigger) by using the aliases OLD and NEW.

OLD.col_name refers to a column of an existing row before it is updated or deleted. NEW.col_name refers to the column of a new row to be inserted or an existing row after it is updated.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading