SQL Server Performance

Trigger based on Insert/Update/Delete

Discussion in 'General DBA Questions' started by netwerkassist, Dec 4, 2007.

  1. netwerkassist New Member

    I'm pretty new to triggers, but have a requirement to update a 2nd table based on Insert, Update and Delete to one main table.

    So when PS_DEPT_TBL has either update, insert or delete action, I need it to update PS_IWAY_CTL table. The columns on PS_IWAY_CTL table include:

    TABLENAME (IE.PS_DEPT_TBL)
    PRIMARY_KEY_1
    ACTION (INSERT, UPDATE, DELETE)
    DATE (CURRENT DATE AND TIME)


    The Primary key on PS_DEPT_TBL is SETID.

    To begin:

    CREATE TRIGGER PS_DEPT_TBL_TRG
    ON HR83ZAP.PS_DEPT_TBL
    AFTER INSERT, UPDATE, DELETE
    AS

    appreciate input
  2. ranjitjain New Member

    Hi,
    Read about create trigger in BOL.Basic idea is that You create a trigger and you get access to virtual tables which stores the rows inserted or rows deleted from prevoius operation into physical table. So in your trigger access rows from such tables and then you can insert those rows or delete those rows into any table you wish
    Read about inserted, deleted virtual tables and also read about cascade delete and insert throughly in BOL which might interests you.
  3. Ronak New Member

    i have same requirement as "networkassist",
    so, if someone fulfill this requirement here with trigger code , i'll very thankful to him.

    appreciate input
  4. Ronak New Member

    I'm pretty new to sqlserver triggers, but have a requirement to update a 2nd table based on Insert, Update and Delete to one main table.

    So when PS_DEPT_TBL has either update, insert or delete action, I need it to update PS_IWAY_CTL table. The columns on PS_IWAY_CTL table include:

    TABLENAME (IE.PS_DEPT_TBL)
    PRIMARY_KEY_1
    ACTION (INSERT, UPDATE, DELETE)
    DATE (CURRENT DATE AND TIME)


    The Primary key on PS_DEPT_TBL is SETID.

    To begin:

    CREATE TRIGGER PS_DEPT_TBL_TRG
    ON HR83ZAP.PS_DEPT_TBL
    AFTER INSERT, UPDATE, DELETE
    AS

    please, give me trigger code for this requirement

    appreciate input
  5. FrankKalis Moderator

Share This Page