sql server触发器引用最后一行

1 sql database sql-server triggers

我想写在SQL Server中的触发器插入2行到table2当行插入table1.我想使用来自的列值table1.

所以我的触发器看起来像这样

create trigger triggername on table1
as
begin
insert into
insert into
end
Run Code Online (Sandbox Code Playgroud)

如何从最后插入的行(触发触发器的行插入)中获取任何列的值.即相当于oracle中的"引用行"

Mar*_*ith 5

SQL Server中的触发器每个语句不触发每行.有两个假表inserted,并deleted可以使用(用于insert触发感兴趣的只有一个是inserted)

CREATE TRIGGER YourTrigger ON Table1
FOR INSERT
AS
INSERT INTO Table2 
SELECT * from inserted /*This will contain multiple rows if it is a multi-row insert*/
Run Code Online (Sandbox Code Playgroud)