Re: help on delete trigger.

Поиск
Список
Период
Сортировка
От Gregory Wood
Тема Re: help on delete trigger.
Дата
Msg-id 012201c124d3$5aae0d20$7889ffcc@comstock.com
обсуждение исходный текст
Ответ на help on delete trigger.  ("Sundararajan" <sdn@srasys.co.in>)
Список pgsql-general
This code looks fine to me, other than missing the actual trigger statement
is missing. Assuming table 1 is named apps:

DROP TRIGGER OnApplicationsDelete ON apps;
DROP FUNCTION ApplicationsDeleteFn();
CREATE FUNCTION ApplicationsDeleteFn()
RETURNS OPAQUE
AS '
 BEGIN
delete from ports where appName=OLD.appName;
 RETURN OLD;

 END;
'
LANGUAGE 'plpgsql';
CREATE TRIGGER OnApplicationsDelete BEFORE DELETE ON apps FOR EACH ROW
EXECUTE PROCEDURE ApplicationsDeleteFn();

But the question is, would it be better to use a foreign key? If you put a
foreign key on ports.appName that REFERENCES apps.appName, you could define
it as an ON DELETE CASCADE relationship. Meaning that deleting the value
from the apps table would cascade that delete to the ports table.

Hope this helps,

Greg




В списке pgsql-general по дате отправления:

Предыдущее
От: Jochem van Dieten
Дата:
Сообщение: PostgresQL equivalent of NOCOUNT
Следующее
От: Craig Longman
Дата:
Сообщение: cmd-line interface