이 트리거는 병원에서 사용 가능한 무료 객실을 업데이트해야합니다. 환자가 방아쇠를 당기면 방이 하나 더 추가됩니다.하지만 방금 작동하지 않아 실제로 이유를 이해할 수 없습니다.업데이트 후 mysql 트리거가 작동하지 않습니다
create table Incidents
(primary key(incident_code),
foreign key(patient_code) references Patients(patient_code)on delete cascade on update cascade,
foreign key(section_code) references Sections(section_code)on delete cascade on update cascade,
foreign key(doctor_code) references Doctors(doctor_code)on delete cascade on update cascade,
incident_code int unsigned,
patient_code int unsigned,
section_code int unsigned,
doctor_code int unsigned,
import_day date not null,
export_day date,
incident_value real not null
check(datediff(export_day,import_day)>-1));
(primary key(section_code),
section_code int unsigned,
section_name varchar(30) not null,
total_rooms int not null,
free_rooms int not null
check(total_rooms>=free_rooms));
이 트리거 코드 : :이 트리거이 테이블을 사용
delimiter @
create trigger FreeRooms1
after update on incidents
for each row
begin
if (old.export_day=null and new.export_day != null)
then
update sections
set free_rooms = free_rooms + 1
where sections.section_code = incidents.section_code;
end if;
end;
@
그리고 이것은 내가 그것을 활성화하기 위해 시도하는 방법이다 :
update incidents
set export_day = '2013/12/24'
where incident_code = 2;
select section_code,section_name,free_rooms
from sections;
,
방아쇠를 여러 번 시도했지만 변경하면 아무 효과가 없습니다. 도움이 필요하십니까? 죄송합니다. 내 질문에 나쁘다면 나는 MySQL에 상당히 익숙하지 않고 어디서나 대답을 찾을 수 없습니다.
delimiter @
create trigger FreeRooms1
after update on incidents
for each row
begin
if (old.export_day IS NULL and new.export_day IS NOT NULL)
then
update sections
set free_rooms = free_rooms + 1
where sections.section_code = NEW.section_code;
end if;
end;
@
을하고 새 행을 참조 :
'='또는'! ='를 사용하여'NULL '을 테스트 할 수 없습니다.'old.export_day가 null이고 new.export_day가 null이 아닌 경우'를 사용해야합니다. –
고마워요. 이 특별한 문법은 당신의 도움없이 그것을 결코 발견하지 못했습니다. – DieCriminal
설명서를 확인하십시오 : http://dev.mysql.com/doc/refman/5.5/en/comparison-operators.html –