Return number of rows affected by UPDATE statements
CREATE PROCEDURE UpdateTables
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @RowCount1 INTEGER
DECLARE @RowCount2 INTEGER
DECLARE @RowCount3 INTEGER
DECLARE @RowCount4 INTEGER
UPDATE Table1 Set Column = 0 WHERE Column IS NULL
SELECT @RowCount1 = @@ROWCOUNT
UPDATE Table2 Set Column = 0 WHERE Column IS NULL
SELECT @RowCount2 = @@ROWCOUNT
UPDATE Table3 Set Column = 0 WHERE Column IS NULL
SELECT @RowCount3 = @@ROWCOUNT
UPDATE Table4 Set Column = 0 WHERE Column IS NULL
SELECT @RowCount4 = @@ROWCOUNT
SELECT @RowCount1 AS Table1, @RowCount2 AS Table2, @RowCount3 AS Table3, @RowCount4 AS Table4
END
TSQL: UPDATE Get num rows updated
To identify the number of rows affected by an operation, you're looking for @@ROWCOUNT
Getting the number of the rows affected by update or insert
When function/trigger is called, the new internal execution state structure is created (PLpgSQL_execstate) with ROW_COUNT value (eval_processed property) set to 0. So inside function you can get ROW_COUNT only for statements inside the same function. As a workaround you can pass sql statement as the text argument to this procedure and execute it inside.
Is a possible to check number of rows affected by update query in oracle without executing the query
You could run EXPLAIN
on your update query. The output from that would include things like row counts at each step of the query pipeline. In addition, EXPLAIN
would be making its estimates using table statistics, rather than hitting the actual production table.
Return number of rows affected by update query?
Try this.
int pg_affected_rows ( resource $result )
http://php.net/manual/en/function.pg-affected-rows.php
Related Topics
Pivot Query on Distinct Records
Where in Condition Not Accepting String Value
Store Multiple Bit Values in a Single Table Column
Stored Procedure That Exports Data into CSV Files Only Exports to One File
How to Select Records with Maximum Values in Two Columns
Get Start and End Date from Week Number SQL Server
In SQL Server How to Pivot for Multiple Columns
Improve SQL Server Query Performance on Large Tables
Run a Query with a Limit/Offset and Also Get the Total Number of Rows
How to Select Every Row Where Column Value Is Not Distinct
Mysql: Compare Differences Between Two Tables
Find All Records Which Have a Count of an Association Greater Than Zero
Difference Between Full Join & Inner Join
Equivalent Function for Dateadd() in Oracle
What Is the Equivalent Postgresql Syntax to Oracle's Connect by ... Start With