내 MySQL의 트리거선언하고 트리거
DELIMITER //
CREATE TRIGGER lestrigger
AFTER INSERT ON examinations
FOR EACH ROW
BEGIN
DECLARE the_last_inserted_id INT ;
DECLARE the_class_id INT;
DECLARE the_year_id INT;
SET the_last_inserted_id = LAST_INSERT_ID();
SET the_class_id = select examination_class_id from examinations where examination_id = the_last_inserted_id;
SET the_year_id = select examination_class_year_id from examinations where examination_id = the_last_inserted_id;
insert into examination_data (ed_cs_id,ed_examination_id) select cs_id from class_students where cs_class_id = the_class_id AND cs_year_id = the_year_id,the_last_inserted_id;
END
//
DELIMITER ;
몇 가지 변수를 선언하고하지만 난이 오류를
/* SQL 오류 (1064)가 계속 변수를 사용 : 당신은 오류가 귀하의 SQL 구문; 라인 10 */
에서 내가 구문 내 변수를 사용하고있는 방법이 있나요 근처 사용할 수있는 권리 구문 MySQL 서버 버전에 해당하는 설명서를 확인 'examination_id = the_last_in 어디 시험 에서 examination_class_id 선택' 권리?.
를 추가해보십시오 괄호. – Hidde
http://seackoverflow.com/questions/12797424/selecting-values-to-a-variable-inside-mysql-triggers – mostruash