2017-11-15 11 views
0
delimiter // 
create trigger tr_emp2 before insert or update 
on employee for each row 
begin 
    if new.ID<>10100 then 
     if new.Mgr not in (select ID from employee) 
     then 
     SIGNAL SQLSTATE '45000' 
     SET MESSAGE_TEXT = 'Invalid Mgr_id!'; 
     end if; 
    end if; 
end;// 
delimiter ; 

"삽입 또는 업데이트 전에 trigger tr_emp를 생성 하시겠습니까?"라고 표현하는 방법은 잘못된 것입니까?MySQL "삽입 또는 업데이트하기 전에 트리거 tr_emp를 생성하십시오"

답변

0

두 개의 트리거를 만들어야하지만 공통 코드를 프로 시저로 옮기고 둘 다 프로 시저를 호출하게 할 수 있습니다.