locked
Trigger After Update affect Another Database RRS feed

  • Question

  • User-1481032724 posted

    hi for ALL

    i have database which have name TEST1,this database have one abc table with tow column ID and Name and i have  TEST2 database which have same table 

    i want make trigger to send data when update  from abc table in TEST1  to abc table in TEST2 

    please help my!!!!

    Thursday, November 17, 2016 11:27 AM

Answers

  • User-2057865890 posted

    Hi Tareq,

    -- UPDATE trigger on "dbo.Table1"
    CREATE TRIGGER Table1Updated
    ON dbo.table1 FOR UPDATE
    AS 
    BEGIN
        -- update table2, using the same rows as were updated in table1
        UPDATE t2
        SET t2.Column = 'something'
        FROM dbo.Table2 t2
        INNER JOIN Inserted i ON t2.ID = i.ID        
    END
    GO

    reference: http://stackoverflow.com/a/24941978 

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 22, 2016 2:30 PM

All replies

  • User364663285 posted

    Hi,

    Here is example for you

    UPDATE t1
    SET    Description = t2.Description
    FROM   db1.dbo.foo t1
           JOIN db2.dbo.foo t2
             ON t1.ItemID = t2.ItemID
    

    to do within your trigger.

    Friday, November 18, 2016 3:10 AM
  • User-2057865890 posted

    Hi Tareq,

    -- UPDATE trigger on "dbo.Table1"
    CREATE TRIGGER Table1Updated
    ON dbo.table1 FOR UPDATE
    AS 
    BEGIN
        -- update table2, using the same rows as were updated in table1
        UPDATE t2
        SET t2.Column = 'something'
        FROM dbo.Table2 t2
        INNER JOIN Inserted i ON t2.ID = i.ID        
    END
    GO

    reference: http://stackoverflow.com/a/24941978 

    Best Regards,

    Chris

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 22, 2016 2:30 PM