How to work after triggering a trigger in SQL Server 2008

I work on a sql server where I want to insert an entry into a specific say (a) table, this table contains two columns [id (identifier field) and name (nvarchar (max)] now after the records are inserted into table (a) , the trigger should start and insert the value of the identifier field in table b .... I use the insert after the trigger for this purpose, but I do not get how I get the value of the identifier field in the trigger ... which should be inserted in table b.

This is what I use

create trigger tri_inserts on (a)
after insert
as
begin
   insert into b (id, name) values (?,?)
end

Please reply as soon as possible .. Thank you and respectfully Abbas Elektravala

+5
source share
2 answers
create trigger tri_inserts on a
after insert
as
set nocount on

insert into b (id, name)
    SELECT id, name FROM INSERTED
GO
+12

@gbn , , , SELECT , VALUES . , //. , . . values, . . VALUES, , . , , 45 , 40 000 . SELECT ( , ) 40 .

+6

All Articles