33 Votes

SQLite: How many rows were affected by an UPDATE or DELETE?

Info by SmartUser | 2013-11-08 at 00:37

Question: We have performed an UPDATE or a DELETE request in our SQLite database. Now we are interested in how many rows from our table have been infected by this. For example, to check whether there were made any changes at all.

Solution: The function changes() helps us in this case. It gives us the number of rows that were affected by the last INSERT, DELETE or UPDATE statement. A call might look like this:

SELECT changes() FROM tab

If you have performed an INSERT, DELETE or UPDATE on the table "tab" before calling this command, the expression gives us the number of rows affected.

If we are interested in the total number of affected rows since connecting to the database, we can use the function total_changes() instead of changes() for this.

ReplyPositiveNegative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.