ErlangBestLanguage
ErlangBestLanguage

Reputation: 74

Creating rules in DB2

In postgres SQL you can create rules which will activate on insert.

So I could make a rule like this and it will activate every time the given conditions are met:

CREATE OR REPLACE RULE person_insert_id_change AS
ON INSERT TO person 
WHERE id = 127777
DO INSTEAD 
INSERT INTO person VALUES (1577761, new.firstname, new.secondname, new.dob);

Is there anyway to achieve something similar in DB2??

Thanks very much!

Upvotes: 0

Views: 144

Answers (1)

mustaccio
mustaccio

Reputation: 19004

In this particular scenario a BEFORE INSERT trigger should do what you want:

CREATE OR REPLACE TRIGGER person_insert_id_change 
BEFORE INSERT ON person 
REFERENCING NEW AS n
FOR EACH ROW
WHEN n.id = 127777
BEGIN ATOMIC
  SET n.id = 1577761;
END

P.S. Not tested, obviously

Upvotes: 1

Related Questions