Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get number of rows affected by ExecuteNonQuery and ignore rows of triggers?

I am using ExecuteNonQuery to run an insert proc, it returns 2, but in actual I am inserting only 1 record. I am getting 1 extra due to trigger. Is there anyway that I get only actual number of rows affected. I do not want the rows affected by trigger.

like image 789
Girish Gupta Avatar asked Aug 25 '15 10:08

Girish Gupta


People also ask

How do you get the number of rows affected by a query?

MySQL ROW_COUNT() can be used to get the total number of rows affected by MySQL query. To illustrate it we are creating a procedure with the help of which we can insert records in a table and it will show us how many rows have been affected.

How can I count the number of rows affected in SQL Server?

Usage. SQL Server @@ROWCOUNT is a system variable that is used to return the number of rows that are affected by the last executed statement in the batch.

Which from the options will retrieve number of rows affected?

The method num_rows() is only useful for determining the number of rows retrieved by a SELECT query. But to retrieve the number of rows affected by INSERT, UPDATE, or DELETE query, use affected_rows().

What is the use of @@ rowcount?

Data manipulation language (DML) statements set the @@ROWCOUNT value to the number of rows affected by the query and return that value to the client. The DML statements may not send any rows to the client.


1 Answers

If you don't have it already, disable counting rows in your trigger:

SET NOCOUNT ON   

For example:

CREATE TRIGGER [dbo].[triggerName] ON [dbo].[TableName]
AFTER INSERT
AS
SET NOCOUNT ON;
......

MSDN

like image 63
Tim Schmelter Avatar answered Oct 21 '22 13:10

Tim Schmelter