This question already has an answer here:
I am doing the exercise about trigger in SQLite and there is a question which asks me write the trigger. The questions follows underneath:
Write one or more triggers to manage the grade attribute of new Highschoolers. If the inserted tuple has a value less than 9 or greater than 12, change the value to NULL. On the other hand, if the inserted tuple has a null value for grade, change it to 9.
Corresponding to this question, I type the code:
create trigger nine
after insert on highschooler
for each row
when new.grade=null
begin
update highschooler
set grade=9
where new.id=id;
end
|
create trigger nu
after insert on highschooler
for each row
when new.grade<9 or new.grade>12
begin
update highschooler
set grade=null
where new.id=id;
end
My code is wrong because I typed new.grade=null in the when statement instead of using new.grade is null. Can somebody explain me the difference between these two codes? Thank you.
Aucun commentaire:
Enregistrer un commentaire