title: How can we update an column with Foreign key constraint in DB2?
body: <p>I have 2 Tables , please check images attached</p>
  
  <p>PK: <a href="https://i.stack.imgur.com/FOD2P.png" rel="nofollow noreferrer">PK</a></p>
  
  <p>FK: <a href="https://i.stack.imgur.com/golf2.png" rel="nofollow noreferrer">FK</a></p>
  
  <p>P_Id in Pk table is the primary key 
  and P_Id in FK table is the foreign key.</p>
  
  <p>I need to add 10 to all records in P_Id column of both PK and FK table( meaning they need to match always)</p>
  
  <p>I know in MS SQL we can easily update cascade as follows:</p>
  
  <pre><code>ALTER TABLE FK
  ADD CONSTRAINT FK_P_Id
  FOREIGN KEY (P_Id)
  REFERENCES PK (P_Id) ON UPDATE CASCADE
  </code></pre>
  
  <p>and then update the rows of PK , which will automatically update FK too.</p>
  
  <pre><code>update A
  set A.P_Id= A.P_Id + 10
  from PK A inner join FK B
  on A.P_Id = B.P_Id
  </code></pre>
  
  <p>But, i am not sure how this works in DB2.. can someone please help?</p>
  
  <p>How can i get this to work?</p>
  
  <p>Thanks in advance
  Swat</p>