Trigger syntax

Hi,
I following some tutorials on SQL triggers but I have a question regarding the syntax, which none of the tutorials i looked at explains:
The aim of my trigger is when the table dbo.RBD_Measure is updated then the trigger fires and (after the update) inserts the Primary Key values from PK column in dbo.RBD_Dimension table into the FK column in dbo.RBD_Measure where RBD columns contain
same values in both table.
I have the code below and it works fine but what i would like to know is what exactly is the difference between having the SQL statements after AS (as in the example below), or having it between BEGIN...END part of the code. Can someone explain what should
come after AS (or what not) and what should come between BEGIN...END?
CREATE TRIGGER [dbo].[Trigger_Update]
ON [dbo].[RBD_Measure]
for insert
AS
update RBD_Measure
Set RBD_Measure.FK=RBD_Dimension.PK
FROM RBD_Measure
INNER JOIN RBD_Dimension
on Rbd_Measure.RBD=RBD_Dimension.RBD
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for trigger here
END
Thanks!

The aim of my trigger is when the table dbo.RBD_Measure is updated then the trigger fires and (after the update) inserts the Primary Key values from PK column in dbo.RBD_Dimension table into the FK column in dbo.RBD_Measure where RBD columns contain
same values in both table.
I have the code below and it works fine but what i would like to know is what exactly is the difference between having the SQL statements after AS (as in the example below), or having it between BEGIN...END part of the code. Can someone explain what should
come after AS (or what not) and what should come between BEGIN...END?
Although it is common practice to specify BEGIN/END to encapsulate the entire code block in triggers (and other modules), it is optional.
Be aware that because you are not joining to the inserted table in your trigger, every row in the RBD_Measure is updated every time this trigger executes regardless of whether the row was inserted by the statement that fired the trigger.  You mention
"after update" but this trigger fires only after INSERT statements.  You can fire the trigger after both inserts and updates, and also join to the inserted table to identify the updated and inserted rows.  Below is an example that assumes the RDB_Measure
table has a primary key column named RBD_Message_PK:
CREATE TRIGGER [dbo].[Trigger_Update_Insert]
ON [dbo].[RBD_Measure]
FOR UPDATE, INSERT
AS
UPDATE m
SET FK = RBD_Dimension.PK
FROM RBD_Measure AS m
INNER JOIN RBD_Dimension AS d
ON m.RBD = d.RBD
INNER JOIN inserted AS i ON
i.RBD_Measure_PK = m.RBD_Measure_PK;
GO
Dan Guzman, SQL Server MVP, http://www.dbdelta.com

Similar Messages

  • Fixing this TRIGGER Syntax

    I am practicing Triggers in SQL Server 2012.  Please help me correct this Trigger Syntax for this practice question below.
     Build a trigger on the emp table after insert that adds a record into the emp_History table and marks IsActive column to 1
    CREATE TRIGGER trgAfterInsert ON [dbo].[emp_triggers] 
    FOR INSERT
    AS
    declare @empid int;
    declare @empname varchar(100);
           declare @isactive int;
    select @empid=i.empid from inserted i;
    select @empname=i.empname from inserted i;
    set   @isactive= 1;
    insert into emphistory
               (empid, empname) 
    values(@empid, @empname, @isactive) ;
    PRINT 'AFTER INSERT trigger fired.'

    Your trigger does not work if an insert statement inserts multiple rows into your emp_triggers table.  Never write triggers that only work correctly when 1 row is inserted, updated, or deleted by one command.  You want
    CREATE TRIGGER trgAfterInsert ON [dbo].[emp_triggers]
    FOR INSERT
    AS
    insert into emphistory
    (empid, empname, isactive)
    select empid, empname, 1 from inserted ;
    which will work correctly no matter how many rows (0, 1, or many) are inserted by one INSERT command.
    Tom

  • Update trigger syntax for multiple collumn update

    Hi
    I would like to create an update trigger that updates 3 collumns in another table.
    This works for one collumn:
    CREATE OR REPLACE TRIGGER DBNAME.Update_EVENT
    BEFORE UPDATE
    ON DBNAME.DB_EVENTS
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    BEGIN
    UPDATE DB_EVENT_LOG ELOG
    SET
    COMPLETION_EVENT = :NEW.COMPLETION_EVENT
         WHERE :OLD.RECORD_ID = ELOG.RECORD_ID ;
    EXCEPTION
    WHEN OTHERS THEN
    -- log the error and re-raise
    RAISE;
    END ;
    but this does not work for multiple collumns:
    CREATE OR REPLACE TRIGGER DBNAME.Update_EVENT
    BEFORE UPDATE
    ON DBNAME.DB_EVENTS
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    BEGIN
    UPDATE DB_EVENT_LOG ELOG
    SET
    (COMPLETION_EVENT
    , COMPLETION_DT_TM
    , COMPLETED_BY)
    =
    (:NEW.COMPLETION_EVENT
    , :NEW.COMPLETION_DT_TM
    , :NEW.COMPLETED_BY)
         WHERE :OLD.RECORD_ID = ELOG.RECORD_ID ;
    EXCEPTION
    WHEN OTHERS THEN
    -- log the error and re-raise
    RAISE;
    END ;
    What am i doing wrong?

    Try selecting from DUAL:
    SQL> CREATE TABLE emp_test AS SELECT * FROM emp
    Table created.
    SQL> CREATE OR REPLACE TRIGGER emp_trg
       AFTER UPDATE
       ON emp
       FOR EACH ROW
    BEGIN
       UPDATE emp_test
          SET (sal, comm) = (SELECT :NEW.sal,
                                    :NEW.comm
                               FROM DUAL)
        WHERE empno = :NEW.empno;
    END;
    Trigger created.
    SQL> UPDATE emp
       SET sal = 5000,
           comm = 5000
    WHERE empno = 7369
    1 row updated.
    SQL> SELECT empno,
           sal,
           comm
      FROM emp_test
    WHERE empno = 7369
         EMPNO        SAL       COMM
          7369       5000       5000

  • Update trigger syntax

    Hi
    I would like to create an update trigger that updates 3 collumns in another table.
    This works for one collumn:
    CREATE OR REPLACE TRIGGER DBNAME.Update_EVENT
    BEFORE UPDATE
    ON DBNAME.DB_EVENTS
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    BEGIN
    UPDATE DB_EVENT_LOG
    SET
    COMPLETION_EVENT = :NEW.COMPLETION_EVENT
         WHERE RECORD_ID = :OLD.RECORD_ID ;
    EXCEPTION
    WHEN OTHERS THEN
    -- log the error and re-raise
    RAISE;
    END ;
    but this does not work for multiple collumns:
    CREATE OR REPLACE TRIGGER DBNAME.Update_EVENT
    BEFORE UPDATE
    ON DBNAME.DB_EVENTS
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    BEGIN
    UPDATE DB_EVENT_LOG
    SET
    (COMPLETION_EVENT
    , COMPLETION_DT_TM
    , COMPLETED_BY)
    =
    (:NEW.COMPLETION_EVENT
    , :NEW.COMPLETION_DT_TM
    , :NEW.COMPLETED_BY)
         WHERE RECORD_ID = :OLD.RECORD_ID ;
    EXCEPTION
    WHEN OTHERS THEN
    -- log the error and re-raise
    RAISE;
    END ;
    What am i doing wrong?

    Your update statement isn't correct, it should look like:
    UPDATE DB_EVENT_LOG
    SET
    COMPLETION_EVENT = :NEW.COMPLETION_EVENT,
    COMPLETION_DT_TM = :NEW.COMPLETION_DT_TM,
    COMPLETED_BY = :NEW.COMPLETED_BY
    WHERE RECORD_ID = :OLD.RECORD_ID ;

  • Need a trigger Syntax

    I want to auto generate invoice No. (inv_ID) user manualy punch date in date field (DATE).
    for example
    when user input date in date field 11-01-2010 and commit the transuction Auto generate (inv_ID) in this format (RRRRMMdd0001).
    201001110001
    201001110002
    201001110003
    if user input date in date field 15-11-2009
    200911150004
    200911150005
    200911150006
    Advance Thanks for yor cooperation
    talk4ever

    Hi,
    I think Manu had given you some solution
    you can twist that to ur own ..
    Try the following code.
    SELECT TO_CHAR(SYSDAYE, 'RRRRmmdd') || NVL(MAX(TO_NUMBER(SUBSTR(ORDER_ID, 9))), 0) + 1 INTO :<block_name>.<field_name> FROM <table_name> WHERE SUBSTR(ORDER_ID, 1, 8) = TO_CHAR(SYSDAYE, 'RRRRMMDD');
    Regards,

  • Can I use a trigger to keep record of deleted data?

    I am trying to log changes to a table, including deletes. The trigger is working effectively for INSERT and UPDATE, but does not capture the data from the row when I create a DELETE trigger.   I have tried various trigger syntax methods to capture the data in a new "log" table, but I only seem to get the key field after the trigger fires.
    My base table has only a few fields:  ID (key), NAME, DESCRIPTION, CREATED_ON, UPDATED_ON.
    On delete, I would like to capture the data that was deleted for record keeping and audit trails.   Below is the latest iteration of my trigger define code:
    create trigger ADDRESS_TYPES_TRIGGER_D
    BEFORE DELETE ON "MEDPORTAL"."MEDPORTAL_XS.data::ADDRESS_TYPES"
    REFERENCING OLD ROW AS thisRow
    FOR EACH ROW
    begin
      declare newId INT;
      declare deleteId INT := 131;
      select "MEDPORTAL"."MEDPORTAL_XS.data::Address_Types_Log_ID".NEXTVAL into newID from DUMMY;
      INSERT INTO "MEDPORTAL"."MEDPORTAL_XS.data::ADDRESS_TYPES_LOG"
      (ID,
      USERNAME,
      ACTION_ID,
      ADDRESS_TYPE_ID,
      NAME,
      DESCRIPTION,
      UPDATED_ON
      values(
      :newId,
      current_user,
      :deleteId,
      :THISROW.ID,
      :THISROW.NAME,
      :THISROW.DESCRIPTION,
      current_timestamp
    end
    This code captures the newId from the sequence as the new table key.  It also captures the USERNAME, ACTION_ID (coded to a delete message in another table), ADDRESS_TYPE_ID (THISROW.ID), and the current_timestamp.  How can I capture the data in NAME and DESCRIPTION in the log table? 
    I have tried
    create trigger ADDRESS_TYPES_TRIGGER_D
    AFTER DELETE ON "MEDPORTAL"."MEDPORTAL_XS.data::ADDRESS_TYPES"
    REFERENCING OLD ROW AS thisRow
    FOR EACH ROW
    and
    create trigger ADDRESS_TYPES_TRIGGER_D
    AFTER DELETE ON "MEDPORTAL"."MEDPORTAL_XS.data::ADDRESS_TYPES"
    FOR EACH ROW
    But I cannot capture the data.  I am on the AWS rev 70 image (1.0.70.386119)
    Is the DELETE trigger capable of capturing the data?

    If you can add a step to disable backup job start of ETL and enable backup job after ETL completes.
    exec msdb..sp_update_job @job_name = 'LS backup Job Name', @enabled = 0 --Disable
    exec msdb..sp_update_job @job_name = 'LS backup Job Name', @enabled = 1 --Enable
    create a record in a table:
    In those line you can create a new job as well which will check record in table if its 0(ETL completed) then enable the backup job and if its 1(ETL running/started) then disable the job. This job will run every 5 mins to check the flag in table. Depending
     on ETL status it will enable or disable tlog backup job that way you will be able to resume log shipping without delay. 

  • Trigger with Nested Table

    How do I reference a column in a nested table in a trigger. I am issuing an update statement:
    UPDATE TABLE (SELECT inv_level
    FROM inventory_level
    WHERE machine_id = '1111'
    SET inventory_level = '15'
    WHERE column_id = '2'
    I want to create a trigger that execute before the insert. I want to insert the machine_id, the column_id, inventory_level into a change history table. The issue is he column_id and inventory_level fields are in the nested table. I tried to reference them as :NEW.column_id, but that didn't work.

    I too have had problems working with triggers & nested tables. This may help
    Imagine the scenario of a table that holds customer data that needs a specific record per user of the database to indicate if they can contact that customer.
    To solve this I created the following
    create type contact_type as object
    (username varchar2(30),
    can_mail number,
    can_phone number);
    create type contact_nt_type as table
    of contact_type;
    --table cust
    create table cust_table(
    custid number,
    custname varchar2(50),
    contact_nt contact_nt_type)
    nested table contact_nt store as contact_nt_tab;
    -- populate tables
    insert into cust_table
    values(1001,'Customer1',
    contact_nt_type(
    contact_type('SCOTT',1,0),
    contact_type('TIMS',0,1)));
    insert into cust_table
    values(1002,'Customer2',
    contact_nt_type(
    contact_type('SCOTT',0,0),
    contact_type('TIMS',0,0)));
    -- view cust_vu
    create or replace view cust_vu
    as
    select ct.custid, ct.custname, nt.can_mail, nt.can_phone
    from cust_table ct, table(ct.contact_nt) nt
    where nt.username = user;
    Now, if scott looks at the customer through the view he sees one set of contact details and if I look I see another. But if we try to update the view we get
    ORA-01733: virtual column not allowed here
    To solve this create an "instead of" trigger
    create or replace trigger cust_vu_update
    instead of update on cust_vu
    for each row
    begin
    -- update the parent table
    update cust_table
    set custname = :new.custname
    where custid = :old.custid;
    -- update the nested table
    update table(
    select contact_nt
    from cust_table
    where custid = :old.custid)
    set can_mail = :new.can_mail,
    can_phone = :new.can_phone
    where username = user;
    end;
    The documentation has a whole section on triggers & nested tables which, for me, did not solve any of my issues. Following the Create trigger syntax, specifically the dml_event_clause, caused me 0600 errors and my session was terminated!
    There may be better solutions but this one works for me.

  • Can any help me in converting oracle trigger to MS SQLSERVER trigger code

    I have two tables t1 and t2.
    Reqmt is: whenever table t1 gets an insert t2 should get updated with corresponding values.
    1 CREATE OR REPLACE TRIGGER tri1
    2 after insert
    3 on t1
    4 for each row
    5 begin
    6 update t2 set c1=:new.c1;
    7* end;
    8 /
    Trigger created.
    Its fine with oracle.
    Note: I have not limited the update with where clause. But, In sqlserver i need that too.
    Thanks in advance
    Raj

    CREATE OR REPLACE TRIGGER "xxx"."TRG_BRAND_STDBY"
    AFTER DELETE OR INSERT OR UPDATE
    ON xxx.BRAND
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    v_dml VARCHAR2(1);
    v_rec VARCHAR2(100);
    BEGIN
    IF (inserting) THEN
    v_dml := 'I';
    v_rec := ' BRAND_ID = '||to_char(:NEW.BRAND_ID);
    END IF;
    IF (updating) THEN
    v_dml := 'U';
    v_rec := ' BRAND_ID = '||to_char(:NEW.BRAND_ID);
    END IF;
    IF (deleting) THEN
    v_dml := 'D';
    v_rec := ' BRAND_ID = '||to_char(:OLD.BRAND_ID);
    END IF;
    insert into replication_queue values
    SEQ_REPLICATION_ID.nextval,
    'BRAND',
    '[email protected]',
    v_rec,
    v_dml,
    sysdate,
    'N'
    insert into replication_queue values
    SEQ_REPLICATION_ID.nextval,
    'BRAND',
    '[email protected]',
    v_rec,
    v_dml,
    sysdate,
    'N'
    insert into replication_queue values
    SEQ_REPLICATION_ID.nextval,
    'BRAND',
    '[email protected]',
    v_rec,
    v_dml,
    sysdate,
    'N'
    EXCEPTION
    WHEN OTHERS THEN
    RAISE;
    END TRG_BRAND_STDBY;
    You can substitute the inserts with updates and try or check the forum/web for after insert trigger syntax and that will help.
    Regards

  • Trigger request

    Hello,
    I want to create a trigger for the following problem:
    Tablename : "distance"
    pos1 : number(5)
    pos2 : number(5)
    distance : number(10,8)
    Both, pos1 and pos2, are foreign keys to a different table with coordinates, and distance is the distance between both. The distance should be entered by the user (but that is not my problem). The problem is, how to create a trigger to ensure that this doesn't happen:
    pos1 | pos2 | distance
    3 | 5 | 100
    5 | 3 | 100
    Because its the same. So I need a trigger that checks both combinations.
    Can you please give me the complete trigger - syntax to create the trigger?
    Thanks a lot,
    Hauke

    This type of constraint can be handled declaratively by a unique index, like this:
    SQL> create table distance
      2  ( pos1 number(5)
      3  , pos2 number(5)
      4  , distance number(11,8)
      5  )
      6  /
    Tabel is aangemaakt.
    SQL> insert into distance values (3,5,100)
      2  /
    1 rij is aangemaakt.
    SQL> insert into distance values (5,3,100)
      2  /
    1 rij is aangemaakt.
    SQL> rollback
      2  /
    Rollback is voltooid.
    SQL> create unique index distance_uk1 on distance(least(pos1,pos2),greatest(pos1,pos2),distance)
      2  /
    Index is aangemaakt.
    SQL> insert into distance values (3,5,100)
      2  /
    1 rij is aangemaakt.
    SQL> insert into distance values (5,3,100)
      2  /
    insert into distance values (5,3,100)
    FOUT in regel 1:
    .ORA-00001: unique constraint (RWK.DISTANCE_UK1) violatedDepending on your requirements, you may even drop the distance column from the unique index.
    Regards,
    Rob.

  • Db trigger that fires when new user created?

    I need to set up a trigger so that whenever a new user is created in our application, user info should be inserted into an application table.
    So I assumed that a trigger on CREATE DDL event will do the trick. But when I looked up trigger syntax, it asks me the schema name on which I want to define the trigger.
    Is it possible to do it at all?

    create or replace trigger create_user_trigger
      after create on database
    begin
      if ora_dict_obj_type = 'USER' then
        -- action
      end if;
    end;
    /

  • Help is greatly needed with page processing in APEX

    hello everyone please could someone help me with a survey application that im working on . Basically i have  a page that has 5 different regions on it an each region has a LOV which has the following display values ( agree, strongly agree, disagree and strongly disagree)  then return values for these are 20 , 50 , 10 and 5 respectively and this is the select from statement to create the LOV below and the table used
    select EVAL_OPTION as display_value, FRM1_REG1 as return_value
    from REL_DIM_SC_TBL
    order by 1
    The LOVs work fine . However when i tried to insert the inputs from the users into another table by means of a page process im getting a error that i cant seem to resolve my tables are :
    REL_DIM_SC_TBL   -- where the display data for the LOV's come from
    REL_DIM_SC_IMP   -- is the table that where the values that the user has selected is stored
    The page items are set up as follows :
       Relationship Dimension Scoring
    JOE  Logout
    WELCOME
      so where you see welcome above is a text field above the regions where the LOV's are and used the select :app_user from dual ; to populate it because in order to insert the data select by the LOV's on the page there has to be an item with a primary key . Which is what i wanted was for the current user using the app to be inserted into the REL_DIM_SC_IMP table . But when i click the submit button i get an error
    below is the select of the automatic DML action i set up under page processing    
    Name
    Page:
    3 Relationship Dimension Scoring
    *Name (Value Required)
    Type:
    Automatic Row Processing (DML)
    Process Point
    *Sequence (Value Required)
    Process Point
    Run Process
    Source: Automatic Row Processing (DML)
    *Table Owner (Value Required)
    *Table Name (Value Required)
    *Item Containing Primary Key Column Value (Value Required)
    *Primary Key Column (Value Required)
    Item Containing Secondary Key Column Value
    Please guys i have been stuck with this for a long time any help at all will be greatly appreciated

    Hello Krunal thanks so much for your reply i did manage to sort out that error how ever there is an other one that im stuck with . Basical i have a table with 6 columns begin score1, score2, score3, score4, form_total, User_id
    What i want to do is create a trigger that adds the four  numeric columns into the form_total
    the trigger syntax i used was
    create or replace trigger "Score_Total_t1"
    AFTER
    insert on "Score_Total"
    for each row
    begin
    :NEW.USER_ID := ('APP_USER');
    :NEW.form_total := ('Score1' + 'Score2 '+ 'Score3' + 'Score4 ');
    end;
    However the :New.USER_ID works fine to input  the currrent user but im getting an error with :NEW.form_total
    Any ideas would be greatly appreciated
    thank you 

  • Can any help me to improve knowledge in OM and Inventory?

    Hi All,
    I am happy to be here. I have been working on Oracle Financial Modules such as GL,AP,PO and AR. But now I want to learn manuafacturing modules also, hope I can learn them very quicky as I am aware of all the process in Auto Invoice, creation of sales orders. If any one has some valuable material in this regard please send it to my mail ID: [email protected]
    I will be very thankful to you. At the sametime if anyone wants to learn financials please let me know, I would send you selfmade material with screenshots and small description, its very valuable material and we can easily understand the process in financials.
    Expecting a positive response from our Oracle family members...
    Thanks,
    Vara

    CREATE OR REPLACE TRIGGER "xxx"."TRG_BRAND_STDBY"
    AFTER DELETE OR INSERT OR UPDATE
    ON xxx.BRAND
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    v_dml VARCHAR2(1);
    v_rec VARCHAR2(100);
    BEGIN
    IF (inserting) THEN
    v_dml := 'I';
    v_rec := ' BRAND_ID = '||to_char(:NEW.BRAND_ID);
    END IF;
    IF (updating) THEN
    v_dml := 'U';
    v_rec := ' BRAND_ID = '||to_char(:NEW.BRAND_ID);
    END IF;
    IF (deleting) THEN
    v_dml := 'D';
    v_rec := ' BRAND_ID = '||to_char(:OLD.BRAND_ID);
    END IF;
    insert into replication_queue values
    SEQ_REPLICATION_ID.nextval,
    'BRAND',
    '[email protected]',
    v_rec,
    v_dml,
    sysdate,
    'N'
    insert into replication_queue values
    SEQ_REPLICATION_ID.nextval,
    'BRAND',
    '[email protected]',
    v_rec,
    v_dml,
    sysdate,
    'N'
    insert into replication_queue values
    SEQ_REPLICATION_ID.nextval,
    'BRAND',
    '[email protected]',
    v_rec,
    v_dml,
    sysdate,
    'N'
    EXCEPTION
    WHEN OTHERS THEN
    RAISE;
    END TRG_BRAND_STDBY;
    You can substitute the inserts with updates and try or check the forum/web for after insert trigger syntax and that will help.
    Regards

  • Update Date field automatically

    When a user is adding a new entry I want two of the fields in the table to be automatically updated without the user knowing (hidden fields), I want a current date and time to be entered into the Updated Date field and the :APP_USER to be entered into the Updated_by VARCHAR2 field.
    How do I go about doing this can I just put code to do so into the source of ITEMS or do I have to create a process?
    Thanks
    s

    S,
    Triggers are a good method, see this thread:
    Re: Table Trigger Syntax
    Jeff

  • How to do update instead of insert / cancel the insert

    Hello,
    we are porting an application, written originally for PostgreSQL, to Oracle. Most of the porting is pretty straightforward - change column types, simple trigger syntax changes etc.
    But we have a table (more precisely several tables) with a set of triggers, holding a tree-like structure. The point is in PostgreSQL we're using a RETURN NULL; behavior in BEFORE triggers, which means 'do nothing' to simplify thing.
    For example imagine tables A and B - and in a trigger on B we could have something like
    INSERT INTO A VALUES (id, ...)
    without a check on a uniqueness of the id value. And in a BEFORE INSERT trigger on A we have something like
    SELECT INTO c id FROM A where id = NEW.id;
    IF FOUND THEN
    UPDATE A SET .... WHERE id = NEW.id;
    -- cancel the insert without an exception
    RETURN NULL;
    END IF;
    which checks for existence of the row, and if it already exists it effectively replaces with UPDATE and cancels the INSERT without an exception.
    Is there something like this in Oracle or do I have to completely rewrite / refactor the whole thing?
    PS: We do have UNIQUE (more precisely PRIMARY KEY) on the columns - I am aware that this is not sufficient to enforce uniqueness in Oracle.

    There are a couple of ways that this could be accomplished in Oracle, although the though of an insert into table b also inserting or updating rows in table a makes me cringe. The easiest way only requires a trigger on table b.
    Something along the lines of:
    SQL> CREATE TABLE a (ID NUMBER PRIMARY KEY, descr VARCHAR2(10));
    Table created.
    SQL> CREATE TABLE b (id NUMBER, descr VARCHAR2(10), descr2 VARCHAR2(20));
    Table created.
    SQL> CREATE TRIGGER b_bi
      2     BEFORE INSERT ON b
      3     FOR EACH ROW
      4  BEGIN
      5     INSERT INTO a VALUES (:new.id, :new.descr);
      6  EXCEPTION
      7     WHEN DUP_VAL_ON_INDEX THEN
      8        UPDATE a SET descr = :new.descr
      9        WHERE id = :new.id;
    10  END;
    11  /
    Trigger created.
    SQL> INSERT INTO a VALUES(1, 'One');
    1 row created.
    SQL> COMMIT;
    Commit complete.
    SQL> INSERT INTO b VALUES(1, 'NewOne', 'New One');
    1 row created.
    SQL> SELECT * FROM a;
            ID DESCR
             1 NewOne
    SQL> INSERT INTO b VALUES(2, 'Two', 'Old Two');
    1 row created.
    SQL> SELECT * FROM a;
            ID DESCR
             1 NewOne
             2 Two
    SQL> COMMIT;
    Commit complete.If you really require the trigger on table a for other reasons, then you could do something like:
    SQL> RENAME a to a_table;
    Table renamed.
    SQL> CREATE VIEW a AS SELECT * FROM a_table;
    View created.
    SQL> CREATE TRIGGER a_ii
      2     INSTEAD OF INSERT ON a
      3     FOR EACH ROW
      4  BEGIN
      5     INSERT INTO a_table VALUES(:new.id, :new.descr);
      6  EXCEPTION
      7     WHEN DUP_VAL_ON_INDEX THEN
      8        UPDATE a_table SET descr = :new.descr
      9        WHERE id = :new.id;
    10  END;
    11  /
    Trigger created.
    SQL> CREATE OR REPLACE TRIGGER b_bi
      2     BEFORE INSERT ON b
      3     FOR EACH ROW
      4  BEGIN
      5     INSERT INTO a VALUES (:new.id, :new.descr);
      6  END;
      7  /
    Trigger created.
    SQL> INSERT INTO b VALUES(2, 'NewTwo', 'New Two');
    1 row created.
    SQL> SELECT * FROM a;
            ID DESCR
             1 NewOne
             2 NewTwo
    SQL> INSERT INTO b VALUES(3, 'Three','Third');
    1 row created.
    SQL> SELECT * FROM a;
            ID DESCR
             1 NewOne
             2 NewTwo
             3 ThreeNeither should require any changes to your application code. However, once agan, I think it is a really bad idea for triggers to have side efects on other tables.
    John

  • Editing triggers is VERY slow

    I am using the latest release of SQL Developer 1.0.0.15.27 on a Windows XP 2002 SP2. I have 1GB of RAM and my processor is 1.86GHz.
    When I click on a specific trigger under a schema in 'Other Users' it takes almost a minute for the trigger window to open. Then I have to click on the edit button in order to see the trigger syntax.
    Other objects do not seem to have this issue and are displayed quickly. What's up with triggers?
    This tool has a lot of potential! Thanks for taking the time to develop a new tool for developers.
    Thanks,
    Brenda

    Hi JGG,
    Thank you for your reply. I forgot to mention that I house my iTunes library on an external drive. I understand that, of course, anything hosted off of my computer would be slower than if it was on my laptop, but this still seems much slower than it was on my older computers (where I also used an external to host the music). Also, I mentioned earlier that if I added music to iTunes that was in a random folder on the external, it would show up instantly on the playlist; but if I added music that was within my iTunes library-folder on the external, it would upload very slowly. Even after it's on the iTunes playlist and "organized" within the Library-folder with the correct titles/folder names, just editing a song (for example, to change the year) would take a long time as well.
    Edit: And, I just realized, there is a big delay when I try to click on a song to play. The little spinning color wheel pops up for a few seconds every single time I click to play a new song out of my playlist. I'm sure that NEVER happened in the past on my old macbook when I also used an external drive.
    Thanks for your help!
    Message was edited by: LappyCat

Maybe you are looking for

  • Incorrect Number of Pages Printing - Custom Paper Size

    Hello Everyone, I am new to Crystal Reports but have recently become responsible for supporting a report that my office has been using for several years.  We utilize a fairly simple Crystal Report to create temporary and guest parking passes in the p

  • Problem in PI7.0 Installation

    Hello all,       I installed newely PI7.0 server. I am not able to open sxmb_ifr. The following error showing.How to resolve this problem. MESSAGE ID: com.sap.aii.utilxi.prop.api.rb_all.NO_PROPERTIES com.sap.aii.utilxi.prop.api.PropertiesException: U

  • Problems With Printing Two Up

    Hi- I have a document that consists of pages that are 5.5x8.5, in other words half of a standard 8.5x11 sheet of paper. I want to be able to print these two up on 8.5x11 sheet of paper. So in the layout section of the print dialog I set pages per she

  • Hiring Employee.

    Hi, I am able to hire an employee through PA40 , it dynamically updates IT0003. I am trying to hire an employee through hr_maintain_masterdata . It does not update IT0003 and produces a short dump . What may be going wrong? Thanks, Rohit

  • Why my external hard drive won't work now

    Hi guys, I have a 500gig USB external harddrive. Today I tried to connect to my macbook mid 2010 and it keeps beeping. When I hear it close to it, it sounds like it start to work for a few seconds and then failed over and over again. I have connected