任務是更新列表klienta_nr
中的特定行,該列位於表klientu_ieteikumi
中。如果在klienti
表中刪除了特定的行。此代碼更新整列而不是特定的行。問題是什麼?SQL,更新特定行中的列而不是所有行
CREATE FUNCTION "funkc"() RETURNS "opaque" AS '
DECLARE
BEGIN
IF (TG_OP = ''DELETE'') THEN
UPDATE klientu_ieteikumi SET klienta_nr = NULL ;
END IF;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';
CREATE TRIGGER "triger"
AFTER DELETE ON "klienti"
FOR EACH ROW EXECUTE PROCEDURE funkc();
這個人做了什麼,我想,反正感謝大家:)
CREATE FUNCTION "funkcija1"() RETURNS TRIGGER AS $$
BEGIN
UPDATE klientu_ieteikumi SET klienta_nr = NULL
FROM klienti WHERE old.klienta_nr = klientu_ieteikumi.klienta_nr;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER "trigeris"
AFTER DELETE ON "klienti"
FOR EACH ROW EXECUTE PROCEDURE funkcija1();
可能在哪裏klienta_ieteikumi.klienta_nr = klienti.klienta_nr;工作? –
我有很多猜測 - 看起來很有希望。 – Randy
好的,但我應該在哪裏放? –