Thread: Triggers

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    Oslo, Norway
    Posts
    2
    Rep Power
    0

    Question Triggers


    Ok I got a question concerning triggers in PL/SQL.

    I'm able to make a trigger that inserts, updates and deletes in table2 when I do an insert, update or delete on table1. My problem is:

    Let's say I have a table with 3 rows and when I insert, update or delete on that table I want another table that include one of those rows to be updated too. I've only managed to "copy" it over if the tables are exactly the same.

    When I try to get 1 field over I get a "not enough values" message. What can I do to get around the fact that I send less attributes than there is in the table I want to update?

    Here is the script I'm trying to use.

    CREATE OR REPLACE TRIGGER Bruker_Insert_Update_Delete
    BEFORE
    INSERT OR UPDATE OR DELETE ON Bruker
    FOR EACH ROW
    BEGIN
    IF UPDATING THEN UPDATE Kopling
    SET BrukerID = :new.BrukerID;
    END IF;

    IF INSERTING THEN INSERT INTO Kopling
    VALUES( :new.BrukerID );
    END IF;

    IF DELETING THEN DELETE FROM Kopling
    WHERE BrukerID = ld.BrukerID;
    END IF;
    END;
    /
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    49
    Rep Power
    11
    Code:
    IF INSERTING THEN INSERT INTO Kopling (columnName)
    VALUES( :new.BrukerID );
    END IF;
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Location
    Oslo, Norway
    Posts
    2
    Rep Power
    0
    Thanks alot

IMN logo majestic logo threadwatch logo seochat tools logo