Trigger executes case value of a column is 'Database I'

0

Create a trigger that automatically enrolls a student in "BD I Laboratory" as soon as it is enrolled in "Database I".

    use Universidade;

insert into Realiza_matricula (RGAacad, Nomedisc) values(20179474911, 'Banco de Dados I');

Delimiter $$
create trigger matricula
after insert on Realiza_matricula
for each row
    BEGIN
        IF (select * From Realiza_matricula Where Nomedisc = 'Banco de Dados I') THEN
            insert into Realiza_matricula values (NEW.RGAacad, 'Laboratorio de BD I', OLD.Date);
        end if;
    END $$
Delimiter;
    
asked by anonymous 20.11.2018 / 18:37

1 answer

0

Uses EXISTS in front of if , "If rows exist ...". Note: Use NOT EXISTS for when not returning rows:

 IF EXISTS(select * From Realiza_matricula Where Nomedisc = 'Banco de Dados I') THEN
            insert into Realiza_matricula values (NEW.RGAacad, 'Laboratorio de BD I', OLD.Date);
        end if;
    
20.11.2018 / 19:11