I have table: " daysoff " and table: " rdv "
the rdv table looks like this :
temps_rdv | etat_rdv | ID_RDV |
---|---|---|
12-10-2022 | reservee | 2 |
the daysoff table looks like this :
ID | DATE_OFF | REASON |
---|---|---|
2 | 12-06-2023 | conge |
i want to insert values in rdv table, but before inserting any thing i need to check first if " temps_rdv " doesn't exist in the daysoff table
example: I can not add a rdv with temps_rdv = 12-06-2023
I tried a trigger, but it doesn't seem to work
CREATE OR REPLACE TRIGGER TRIGGER1
BEFORE INSERT ON rdv
FOR EACH ROW
BEGIN
IF EXISTS (
select daysoff.date_off
From Available daysoff -- CHANGED THE ALIAS TO A
where (NEW.temps_rdv = daysoff.date_off)
) THEN
CALL:='Insert not allowed';
END IF;
END;
I also tried this :
CREATE TRIGGER TR2
BEFORE INSERT ON RDV
FOR EACH ROW
DECLARE found_it INT;
-- IF (NEW.temps_rdv != "01-01-23" AND NEW.temps_rdv != "02-01-23" AND NEW.temps_rdv != "03-01-23" ) THEN
BEGIN
SELECT COUNT(1) INTO found_it FROM daysoff
WHERE NEW.temps_rdv != "01-01-23" AND NEW.temps_rdv != "02-01-23" AND NEW.temps_rdv != "03-01-23";
IF (found_it = 0) THEN
INSERT INTO rdv (temps_rdv, etat_rdv, id_rdv, patient_id_p) VALUES (NEW.temps_rdv, NEW.etat_rdv, NEW.id_rdv, NEW.patient_id_p);
END IF;
END IF;
END;
but none of these worked