Sql Server trigger insert values from new row into another table
try this for sql server
CREATE TRIGGER yourNewTrigger ON yourSourcetable
FOR INSERT
AS
INSERT INTO yourDestinationTable
(col1, col2 , col3, user_id, user_name)
SELECT
'a' , default , null, user_id, user_name
FROM inserted
go
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.