1

Topic: set nocount on and @@ rowcount

Respected, prompt please. Why at me the option set nocount on drops @@ rowcont in the trigger in 0, it so should be?

create table a (id int, name varchar (10))
go
create trigger a_update on a
for update
as
begin
set nocount on
if @@ rowcount = 0 return
if exists (select 1 from inserted i join deleted d on i.id = d.id and i.name <> d.name)
begin
raiserror (' abort update ', 16, 1)
rollback transaction
return
end
end
go
insert into a (id, name) values (1, ' a ')
go
update a set name = ' b ' where id = 1
go
drop table a
go

If in this example  set nocount on the trigger fulfills that, differently takes off from the trigger on the first If

2

Re: set nocount on and @@ rowcount

Bekzod;
These damned helps, never read them, well at least till a dinner

wrote:

Statements such as USE, SET <option>, DEALLOCATE CURSOR, CLOSE CURSOR, BEGIN TRANSACTION, or COMMIT TRANSACTION reset the ROWCOUNT value to 0.

3

Re: set nocount on and @@ rowcount

Well and more  check

IF NOT EXISTS (SELECT 1 FROM INSERTED) RETURN;

4

Re: set nocount on and @@ rowcount

TaPaK wrote:

Bekzod;
These damned helps, never read them, well at least till a dinner
it is passed...

, here it that

TaPaK wrote:

well and more  check

IF NOT EXISTS (SELECT 1 FROM INSERTED) RETURN;

Counted on @@ rowcount )) yes I will remain on this variant. Thanks))

5

Re: set nocount on and @@ rowcount

Bekzod;
@@ROWCOUNT not a successful choice at usage MERGE so on a choice well and it is natural 1 the instruction, SET NOCOUNT ON it is possible and then

6

Re: set nocount on and @@ rowcount

TaPaK;
In my case it is better to refuse generally from @@ rowcount.  and triggers not only I correct, suddenly it is not pleasant to someone that set nocount on not in the beginning and again 25))