Sql Server trigger insert values from new row into another table Sql Server trigger insert values from new row into another table sql-server sql-server

Sql Server trigger insert values from new row into another table


try this for sql server

CREATE TRIGGER yourNewTrigger ON yourSourcetableFOR INSERTASINSERT INTO yourDestinationTable        (col1, col2    , col3, user_id, user_name)    SELECT        'a'  , default , null, user_id, user_name        FROM insertedgo


You use an insert trigger - inside the trigger, inserted row items will be exposed as a logical table INSERTED, which has the same column layout as the table the trigger is defined on.

Delete triggers have access to a similar logical table called DELETED.

Update triggers have access to both an INSERTED table that contains the updated values and a DELETED table that contains the values to be updated.


You can use OLDand NEW in the trigger to access those values which had changed in that trigger. Mysql Ref