sql server触发器引用最后一行
我想在 SQL Server 中编写一个触发器,以便在向 table1
中插入一行时,向 table2
中插入 2 行。我想使用 table1
中的列值。
所以我的触发器看起来像这样
create trigger triggername on table1
as
begin
insert into
insert into
end
How do I get the value of any columns from the Last插入的行(触发触发器的行插入)。即相当于oracle中的“引用行”
I want to write a trigger in SQL Server to insert 2 rows into table2
when a row is inserted into table1
. I want to use a column value from table1
.
So my trigger looks like this
create trigger triggername on table1
as
begin
insert into
insert into
end
How do I get the value of any column from the last inserted row (the row insertion which fires the trigger). I.e. the equivalent of 'referencing row' in oracle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SQL Server 中的触发器按语句而不是按行触发。您可以使用两个伪表
inserted
和deleted
(对于insert
触发器,唯一感兴趣的是inserted
代码>)Triggers in SQL Server fire per statement not per row. There are two pseudo tables
inserted
anddeleted
that you can use (for aninsert
trigger the only one of interest isinserted
)你好
我自己有解决方案。我错过了别名
select @patent_no=fldL1BasCode from insert
应该是
select @patent_no=i.fldL1BasCode from insert i
hi
i have the solution myself. i missed the alias
select @patient_no=fldL1BasCode from inserted
should be
select @patient_no=i.fldL1BasCode from inserted i