Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Over the past year I have found your site to be EXCELLENT. Never have I been able to find so many answers to such vast problems and it is an excellent service..."

Geography

Where in the world do Tek-Tips members come from?
tyb (TechnicalUser)
15 Apr 04 4:20

 dear frends

  i've a master table "purchase_orders" which has a quantity column
 and a detailed table "styles" containing a quantity column

 now the quantity column in "Purchase_order" is the sum of all the quantities in the "styles" relavant to that Purchase Order in the styles table.

 i want the PO quantities to be updated with the summ of all the styles quantities on either Insert, update or delete.

 plz help me

  thanks in advance.
 
HimanB (IS/IT--Management)
28 Apr 04 6:06
Hi,
Write an "After INSERT or UPDATE or DELETE trigger for Each row" on Styles table.


If INSERT then
  L_qty:=:new.qty; --- Qty of Styles table.
  Update PO table
  set qty=qty+L_qty
  where ...........
elsif UPDATE then
  L_qty:=:new.qty - :old.qty;
  Update PO table
  set qty=qty+L_qty
  where ...........
else
  L_qty:=:old.qty;
  Update PO table
  set qty=qty - L_qty
  where ...........
end If;

HTH
Regards
Himanshu
BJCooperIT (Programmer)
28 Apr 04 7:23
Having a child table update the parent row may cause locking problems. It will cause problems with "record updated by another user" in forms. It will also degrade performance.

This is a non-normalized database design which should be avoided if possible.

Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Systems Project Analyst/Custom Forms & PL/SQL - Oracle/Windows

tyb (TechnicalUser)
29 Apr 04 4:32
thanks Himan & BJ for ur responses.

 Himan !

 i dont know how to write a trigger.

 is it 2b written in sql or forms. also plz enclose the whole body,

 many cardial thanx

 
HimanB (IS/IT--Management)
29 Apr 04 7:02
Hi,
Here I am talking about Database triggers.
So you need to fire the following Script in your Database directly to create a trigger Named ALST0001 which will fire whenever you Insert/Update or Delete record from Styles table.
Also do not forget to change the where clause in this script as i do not know on what keys you have made relationship between your tables.

Regards
Himanshu

CODE

CREATE OR REPLACE TRIGGER ALST0001
    AFTER
    INSERT OR UPDATE OR DELETE ON STYLES
    FOR EACH ROW
DECLARE
 L_QTY  NUMBER(10);
BEGIN
   IF INSERTING THEN
      L_QTY:=:NEW.QTY;
      UPDATE PURCHASE_ORDERS
      SET QTY = QTY + L_QTY
      WHERE ORDERNO = :NEW.ORDERNO; /**OR WHATEVER THE FEILDS ON WHICH YOU HAVE A RELATION BETEWEEN YOUR TABLES**/
   ELSIF UPDATING THEN
      L_QTY:=:NEW.QTY - :OLD.QTY; /**IF YOU AR INCREASING QTY IN STYLES THEN THIS +VE IF DECREASING THEN -VE **/
      UPDATE PURCHASE_ORDERS
      SET QTY = QTY + L_QTY
      WHERE ORDERNO = :NEW.ORDERNO; /**OR WHATEVER THE FEILDS ON WHICH YOU HAVE A RELATION BETEWEEN YOUR TABLES**/
   ELSE
      L_QTY:=:OLD.QTY;
      UPDATE PURCHASE_ORDERS
      SET QTY = QTY - L_QTY
      WHERE ORDERNO = :NEW.ORDERNO; /**OR WHATEVER THE FEILDS ON WHICH YOU HAVE A RELATION BETEWEEN YOUR TABLES**/
   END IF;
END;

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close