20

I have a query which do UPSERT or update if exists and insert if not:

update MyTable 
set [Name]=@NewValue 
where ID=@ID

If @@RowCount = 0 
insert into MyTable([Name])
values(@Name)

Now, I wonder if the @@RowCount will be affected by a query executed in a trigger? Let us say in my trigger I have:

insert into MyLogs(Description) 
values("Some description...")

If the update is successful in my first query, the trigger will run the insert to MyLogs which will have affected rows.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
kazinix
  • 28,987
  • 33
  • 107
  • 157

1 Answers1

20

@@ROWCOUNT is tied to the scope of your current execution and is therefore unaffected by a trigger, which would run in a different scope.

Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235