从分配了触发器的行访问数据

Accesing the data from a row where trigger is assigned

我在设计这个触发器的时候遇到了一个问题:

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');

基本上。当触发器命中时,我想从 classassignment 中新插入的行访问数据,并在子查询中使用它,该子查询将从与 'data accesed from table where trigger hits' 相关的学生 table 中提取数据。 希望我已经说清楚了。谢谢=)

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

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.