编写一个触发器,让新学生像其他人一样自动命名为“友好”。也就是说,在触发器运行之后,我们应该在Likes表中为每个其他与“友好”相同等级的高中学生A拥有('友好',A)。
create trigger R1
before insert on Highschooler
for each row
when New.name="Friendly"
begin
insert into Likes
Select New.ID,ID from Highschooler where grade = New.grade ;
end;
答案 0 :(得分:0)
Oracle触发器代码
create trigger R1
before insert on Highschooler
for each row
when New.name="Friendly"
begin
insert into Likes
Select New.ID,ID from Highschooler where grade = New.grade ;
end;
此MySQL触发器代码的行为应与Oracle触发器代码相同。
delimiter $$;
create trigger R1
before insert on Highschooler
for each row
begin
if NEW.name = "Friendly" then
insert into Likes Select New.ID,ID from Highschooler where grade = New.grade ;
end if;
end$$
delimiter;