2017-12-20 2 views
1

다른 열이 업데이트 될 때 열을 업데이트하기 위해 Firebird 2.5에 트리거를 만들려고합니다. 내 시도를 위해 간단한 예제 테이블을 만들었습니다. AFTER UPDATE 트리거시 읽기 전용 열 오류 업데이트 시도

create tablea (estado char(1), fl_previa_laudo char(1)); 

그리고 내 트리거는 다음과 같이이다 :

create trigger ATUALIZA_PREVIA_AI for TABLEA 
active after update position 0 
as 
begin 

if(old.estado in ('3', '4', '7', '8')) then 
    new.fl_previa_laudo = 'T'; 
else 
    new.fl_previa_laudo = 'F'; 
end; 

을 내가 방아쇠를 실행할 때 오류 제공합니다

can't format message 13:849 -- message file C:\Windows\firebird.msg not found. attempted update of read-only column.

답변

1

당신은 AFTER UPDATE 트리거의 열을 수정하려고를 하지만 그건 불가능합니다. 값을 수정하려면 BEFORE UPDATE 트리거를 사용해야합니다. Firebird documentation on triggers에 참조, 특히 (강조 광산) : 즉

The NEW and OLD variables are subject to some rules:

  • In all triggers, the OLD value is read-only
  • In BEFORE UPDATE and BEFORE INSERT code, the NEW value is read/write, unless it is a COMPUTED BY column
  • In INSERT triggers, references to the OLD variables are invalid and will throw an exception
  • In DELETE triggers, references to the NEW variables are invalid and will throw an exception
  • In all AFTER trigger code, the NEW variables are read-only

before update 트리거에 당신을 수 행이 지속되기 전에 행 후 after update 트리거 화재가 지속하고있는 동안 당신이 값을 수정할 수 있습니다 최종 값을보십시오.

+0

작동합니다! 고마워요! –

+0

@diegopereira 내 답변이 문제를 해결하는 데 도움이 되었다면 동의 버튼 (체크 표시)을 클릭하여 내 대답을 '수락'하십시오. –

관련 문제