title: Implementing Oracle Database Triggers
body: <p>Below is the code snippet which I need to improve.</p>
  
  <pre><code>CREATE OR REPLACE T_CHANGE AFTER ---Trigger Created for After insert/update option
  INSERT OR 
  UPDATE OF QTY ON ABC BEGIN 
  IF INSERTING THEN 
  UPDATE XYZ D SET FLAG_CHG = 1 
  WHERE EXISTS 
  (
  SELECT 1 FROM XYZ D WHERE 
  :NEW.PRODUCT = D.PRODUCT AND 
  :NEW.LOCATION = D.LOCATION 
  );
  
  IF UPDATING THEN 
  UPDATE XYZ D SET FLAG_CHG = 1 
  WHERE EXISTS 
  (
  SELECT 1 FROM XYZ D WHERE 
  :OLD.PRODUCT = D.PRODUCT AND 
  :OLD.LOCATION = D.LOCATION `enter code here`
  );
  
  END IF 
  END T_CHANGE;
  
  The two mentioned tables are as follow:
  
  CREATE TABLE XYZ (
  PRODUCT VARCHAR2(50),
  LOCATION VArchar2(50),
  FLAG_CHG BOOLEAN DEFAULT 0,
  CONSTRAINT XYZ_PK PRIMARY KEY (PRODUCT,LOCATION)
  )
  
  CREATE TABLE ABC (
  PRODUCT VARCHAR2(50),
  LOCATION VArchar2(50),
  QTY NUMBER,
  CONSTRAINT ABC_PK PRIMARY KEY (PRODUCT,LOCATION)
  )
  </code></pre>
  
  <p>What are you trying to achieve ?</p>
  
  <p>1)If the QTY in ABC is updated or inserted the FLAG_CHG in XYZ should be updated to 1.</p>
  
  <p>I have few queries on this </p>
  
  <pre><code>1.) Will the above code work? :P
  2.) If works, will it have performance issues ?
  3.) How can I enhance this code to improve the performance ?
  4.) Please advice a better approach ,if any,to fulfill the requirement?
  </code></pre>
  
  <p>Thanks in Advance.</p>