PostgreSQL Question: Delete after: So lets say I have two tables test1_tbl and t
ID: 3918997 • Letter: P
Question
PostgreSQL Question: Delete after:
So lets say I have two tables test1_tbl and test2_tbl :
Create table test1_tbl(id Integer Not NULL Primary Key, name text);
Create table test2_tbl(id Integer Not NULL Primary Key References test1_tbl(id), name text);
NOW, What I want to do is create a trigger that automattically deletes a record from table 1 if I delete a record from table 2
Similar to this
Delete from table2_tbl where id = 1;
(IF I RUN THIS I want something like this to execute below because of a trigger)
Delete from table1_tbl where id = 1);
Explanation / Answer
DELIMITER $$
CREATE TRIGGER tgr_1 AFTER DELETE ON table2_tbl
FOR EACH ROW
BEGIN
DELETE FROM table1_tbl where id = old.id;
END $$
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.