Reputation: 25
Hello,
I'm really new to sql and I only know the basics of it, so i am having some dificulties.
How do i populate tables with a trigger?. To be more specific i want to pass the primary key to another table, let's say for example i want to pass id_Academista (PK) from Table Academista to id_Academista (FK) on table Habilitacoes.
At this point i have something like this:
CREATE OR REPLACE TRIGGER ADDCOMP
AFTER INSERT ON ACADEMISTA
FOR EACH ROW
BEGIN
INSERT INTO Habilitacoes(id_academista)
VALUES((SELECT ID_ACADEMISTA FROM academista));
END;
I test the code on Oracle, but i think it doesn't make any sense.
Upvotes: 0
Views: 409
Reputation: 2592
You should use :new.id_Academista
in order to insert the value in other table. Try the below code:
CREATE OR REPLACE TRIGGER ADDCOMP
AFTER INSERT ON ACADEMISTA
FOR EACH ROW
BEGIN
INSERT INTO Habilitacoes(id_academista)
VALUES((:new.id_Academista));
END;
Here parameter :new
represents the latest row you have inserted in the table Academista
.
Upvotes: 2