Questions tagged [rows-affected]

The number of rows affected by executing a SQL Query

The number of rows affected by executing a SQL Query.

The @@ROWCOUNT variable will return the number of rows affected by the last executed query in SQL Server

65 questions
19
votes
2 answers

Getting the number of affected rows for a SQLite statement using the C API

I'm executing a DELETE statement using the SQLite 3 C API, and I'd like to know how to fetch the number of affected rows. Unfortunately, there is no function such as sqlite3_affected_rows or similar.
netcoder
  • 66,435
  • 19
  • 125
  • 142
11
votes
3 answers

UPDATE/DELETE in mysql and get the list of affected row ids?

Is there an efficient way to get the list of affected row IDs (not the # of affected rows via PHP's mysql_affected_rows(), but the actual row ids that were affected) from an UPDATE or DELETE query in mysql? In postgresql, there is a RETURNING clause…
archmeta
  • 1,107
  • 4
  • 17
  • 29
10
votes
1 answer

Why affected_rows always returns -1?

I seem to have problem getting affected_rows when I INSERT and SELECT, it just returns -1 for some reason? I'm using a database class which I use all the time for my projects which uses MYSQLI prepare statements to avoid SQL injections. Does anyone…
John
  • 387
  • 2
  • 5
  • 17
10
votes
4 answers

How to determine if a MySQL update query succeeded when the data passed in the query is the same as what is already in the database?

Let's say you have a form with pre-populated data from your database, and you allow your users to make changes and save the form. If the user clicks the save button without making any changes, MySQL will not actually perform a write operation, and…
Kyle Noland
  • 4,788
  • 6
  • 30
  • 33
8
votes
2 answers

What can cause 'rows affected' to be incorrect?

Using Microsoft SQL Server Management Studio 2008. I have done a simple transaction: BEGIN TRAN SELECT ko.ID, os.ID AS ID2 FROM table_a AS ko JOIN table_b AS os ON os.ID=ko.ID WHERE (ko.the_date IS NOT NULL AND os.the_date IS NULL); UPDATE table_b…
Indrek
  • 6,516
  • 4
  • 29
  • 27
7
votes
2 answers

MySQL no affected rows upon UPDATE when value not changed

MySQL with PHP, trying to update a row: $dbQuery = 'UPDATE UserTable SET Age=25 WHERE Id=3'; $result = mysqli_query($dbLink, $dbQuery); if ($result === FALSE) { // Take care of error } else { $numAffectedRows =…
Free Bud
  • 746
  • 10
  • 30
6
votes
2 answers

mysql_affected_rows() returns -1

When executing an SQL statement, such as INSERT INTO table ... ON DUPLICATE KEY UPDATE ... I rely on mysql_affected_rows() to determine if an insert or an update was performed. as the mysql site on…
yirmi
  • 61
  • 1
  • 2
5
votes
1 answer

PHP affected_rows returns negative 1 (-1)

This is quite strange, the query executes just fine and inserts the data into the table, but my affected rows shows on the negative side rather than 1. Does anyone know why this is happening? connect.php:
Dylan de St Pern
  • 469
  • 1
  • 7
  • 20
4
votes
1 answer

php mysqli affected_rows

I'm just doing some testing with this, and I cant figure out if I am doing this the correct way. The query will update the row.. But the affected_rows always returns 0.. Why?
Chris
  • 461
  • 3
  • 9
  • 16
4
votes
1 answer

mysql insert on duplicate key update, check which one occurred

In PHP, how to detect which one happened (INSERT or UPDATE) in the following query: INSERT INTO ... ON DUPLICATE KEY UPDATE ...
Aliweb
  • 1,891
  • 3
  • 21
  • 44
4
votes
2 answers

sp_send_dbmail: avoid (n rows affected)

Calling sp_send_dbmail: successful execution, but at the ends appear an extra line with rows affected by the query. Is there any way to avoid thiks line? Thanks!!!
user2061430
  • 41
  • 1
  • 2
3
votes
1 answer

mysqli_affected_rows return -1 but update query is successful

I have a page of php code take user's new password string to change user password and after some validation code send to process page for update record in users table. after sending new password string to process page and doing the update query,…
harix
  • 277
  • 3
  • 15
3
votes
1 answer

MySQL ROW_COUNT() not working in Prepare statement

What I'm doing. I've a procedure where I'm deleting rows. I'm getting var_SelectedIds as , separated UUID() then SET @var_SQLStr = ''; SET @var_SQLStr = CONCAT(@var_SQLStr ,'Delete '); SET @var_SQLStr = CONCAT(@var_SQLStr ,'FROM…
Kaushik
  • 2,072
  • 1
  • 23
  • 31
3
votes
1 answer

Differentiate between 'no rows were affected' and rows succesfully UPDATEd--to same value (MySQL and PHP)

I am executing SQL (MySQL) commands from PHP. There are several possible outcomes to each execution: Record updated to new value Record updated, but values happen to be the same Record finds no rows to update (ie, no rows match the WHERE clause) I…
Jo.P
  • 1,139
  • 4
  • 15
  • 35
3
votes
1 answer

Codeigniter db->update() VS MySQL native UPDATE Affected rows: 0

Using MySQL alone - If I make a basic update to a table like this: UPDATE `SOMETABLE` SET `NAME` = 'John' WHERE `ID` = 1; And the value of NAME = 'John' was already 'John' - in other-words - nothing is new, nothing to update. MySQL returns…
user1502852
1
2 3 4 5