본문 바로가기
MySql

MySQL 특정 조건에서 INSERT를 방지하는 MySQL 트리거

by 베이스 공부 2020. 11. 22.
반응형

생년월일 (열 중 하나)이 미래인 경우 삽입을 방지하는 트리거를 만들고 싶습니다. 나는 이것을 가지고있다:

CREATE TRIGGER foo
BEFORE INSERT ON table
FOR EACH ROW
BEGIN
  IF NEW.birthdate > CURRENT_DATE()
  THEN
    //How do I prevent the insert right here???
  END IF;
END;

if 문 내에서 삽입을 취소하려면 어떻게해야합니까?

 

해결 방법

 


MySQL의 현재에는 지원이 없습니다. implementation of triggers to voluntarily throw an exception and abort the statement that spawned the 방아쇠.

내가 찾은 해결 방법은 a BEFORE trigger to set one of the not-NULL columns in the table to NULL, thus violating its NOT NULL constraint. This causes the statement that spawned the trigger to be 중단되었습니다.

 

참조 페이지 https://stackoverflow.com/questions/2981930

 

 

반응형

댓글