Results 1 to 4 of 4

Thread: SQL - Triggers

  1. #1
    Join Date
    Nov 2012
    Posts
    2

    Unanswered: SQL - Triggers

    nothing interesting here

    Thanks
    Last edited by Dralos; 11-24-12 at 19:38.

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    See a picture of my care that doesn't work.
    Tell me how to make my car go.

    Since we don't have your tables or data, we can not compile, run or test posted code.

    What is NULL+1 equal to?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Nov 2012
    Posts
    2
    sorry for wasting your time, i found it.

    Thanks
    Last edited by Dralos; 11-24-12 at 19:38.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by Dralos View Post
    - Hello all

    I have a question regarding Triggers...

    Lets say that we have two tables.

    table1(p_id,gain,month)

    table2(p_id,gain_sum)

    for example i insert for p_id=3 for 4 months a different gain.

    I just want in to make a trigger for table2 , so that when i insert something to table1 then table 2 automatically gets updated with the sums.


    I have tried this: (but it doesn't really work). Any ideas there ?

    Code:
     CREATE TRIGGER sums after INSERT ON table1 
    FOR EACH ROW
    BEGIN
    UPDATE table2 SET gain_sum=gain_sum+table1.gain 
    WHERE table1.p_id = table2.p_id; 
    END;
    Thanks
    Glad to see that you got your question answered!

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •