SQL Server Performance

Trigger Help - Newbie

Discussion in 'General Developer Questions' started by gems22, Aug 7, 2007.

  1. gems22 New Member

    Hi All,

    This is my first time writing a trigger in SQL Server 2000. Needed some guidance with syntax. I have a table(table1) with exact same copy(table2) in a different database. The only difference in the table structure being that two fields from table1 are concatenated into one in table2.
    I want to write a trigger that will keep table2 in sync with table1. Whether it's an insert, delete or an update on table1, table2 should be the same. Need some help with the syntax.
    This is what I have so far..I am little confused about insert/update syntax. Any help will be highly appreciated.
    CREATE TRIGGER TRG_DC ON [dbo].[TABLE1]
    FOR INSERT, UPDATE, DELETE
    AS
    DECLARE @DC VARCHAR(5)
    SELECT @DC = (SELECT do_group+do_ssc FROM INSERTED)
    DELETE FROM TABLE2
    WHERE ID IN (SELECT ID FROM DELETED)
    Thx
  2. Adriaan New Member

    You don't need the @DC variable - you can join on concatenated columns. However, I would suggest that you reconsider the concatenated column on Table2, because this will ruin performance more and more as the number of rows grows on either end.

Share This Page