INSERT INTO 对TRIGGER只能单条触发吗?

Billie_li 2002-03-11 10:23:22
INSERT INTO 对TRIGGER只能单条触发吗?
...全文
120 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Billie_li 2002-05-07
  • 打赏
  • 举报
回复
可是我要对插入的多行进行逐行判断再作操作,那该怎么办?
Billie_li 2002-04-24
  • 打赏
  • 举报
回复
怎么样对inserted表不用游标而直接进行多行操作,我没想明白。

可否指点?举个例子行吗?
dlkfth 2002-04-24
  • 打赏
  • 举报
回复
SQLSERVER触发器是单行触发
zbjin 2002-04-24
  • 打赏
  • 举报
回复
create trigger example
on table1
for insert
as
insert into table2 (field1,field2)
select field3,field4 from inserted
yannankai 2002-04-02
  • 打赏
  • 举报
回复
用游标一般是不得已的情况下才使用。
我以前也是总用游标,后来用的少,
以后你也会减少游标的使用的
x_zing 2002-04-02
  • 打赏
  • 举报
回复
对啊,用insert into 就不要用游标啦。
prjM 2002-04-02
  • 打赏
  • 举报
回复
可以多条。并且不需要用游标,直接对inserted表进行多行操作即可。
Billie_li 2002-03-11
  • 打赏
  • 举报
回复
我就是这样写的呀

Sscript:
CREATE trigger ins_Table on [dbo].[Table]
for insert
as
declare @rows_inserted int
select @rows_inserted = count(*) from inserted

set nocount on
if (@rows_inserted = 1) --只插入一行
begin
--some scripts
end
else --有多行,用游标
begin
declare @rowguid uniqueidentifier
declare ins_cursor cursor local fast_forward for
select rowguid from inserted
open ins_cursor
fetch next from ins_cursor into @rowguid
while @@fetch_status = 0
begin
--some scripts
fetch next from ins_cursor into @rowguid
end
close ins_cursor
deallocate ins_cursor
end
return


可执行完,发现只对第一行操作有效
yannankai 2002-03-11
  • 打赏
  • 举报
回复
不是吧,如果你写成insert into *** select * from abc
这样就不可能还是单条触发了

34,874

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧