I’ve never created a trigger before and I’m trying to read online but am a little confused.
I want to create a trigger on a table that on insert, it will grab some data from different columns and insert it into a few different other tables.
I’m not sure how to write the T-SQL to get the data from the columns..
insert into [othetTable]
values ([col1 from row that was inserted], [col5 from row that was inserted])
What would the syntax be to get those values?
thanks
Use the
insertedvirtual table that is available to triggers. Note that there could be multiple rows in this table – your trigger could be processing multiple inserts at once.Therefore, you need to use something like the following syntax:
This will insert a row into
othertablefor each inserted row.