HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

DB2 Trigger: only update current row

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
triggerupdatedb2currentrowonly

Problem

I've created following trigger :

CREATE TRIGGER probeer2
  AFTER INSERT ON libtn01leb.kofax_release
  FOR EACH ROW
  UPDATE libtn01leb.kofax_release SET RRNR='bleh'


This trigger will update EVERY ROW in the table, instead of the row I'm currently adding.
How can I make it only be valid for the row I'm inserting ?

Solution

Your UPDATE statement is wrong. It is updating all the records in the table because it doesn't have any WHERE clause. If you want to update only the current row, you need to use the updated/inserted records (like in Jack's example: REFERENCING NEW AS N_ROW and use it as filter).

Context

StackExchange Database Administrators Q#2556, answer score: 5

Revisions (0)

No revisions yet.