mardi 3 décembre 2019

MySQL check if the table only contains this certain type

delimiter $$
CREATE Trigger TreeTest 
after insert on trees

for each row
begin
    if (select type from trees) != 'oak' OR (select type from trees ) != 'burch' OR (select type from trees ) != 'maple' OR (select type from trees ) != 'tulpin' then
 set message_text = 'You do not have the right tree';
     end if;
end; $$
delimiter ;

I use this code in MySQL but it always alarms the trigger with the data from the table while it shouldn't Where did I go wrong?

The goal is to check if only these three types are in the table. If not give an error.

Aucun commentaire:

Enregistrer un commentaire