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