SQLite changes() Function

The SQLite changes() function returns the number of rows affected by the last INSERT, UPDATE, or DELETE statement.

Syntax

Here is the syntax of the SQLite changes() function:

changes()

Parameters

The SQLite changes() function does not require any parameters.

Return value

The SQLite changes() function returns an integer that is the number of rows affected by the most recently completed INSERT, UPDATE, or DELETE statement .

Examples

To demonstrate what the SQLite changes() function can do, we create a table with the following statement test_changes using the following statement:

CREATE TABLE test_changes (
    id INTEGER PRIMARY KEY,
    note VARCHAR(100)
);

Let us insert 2 rows using the following INSERT statement,

INSERT INTO test_changes (id, note)
VALUES (1, 'Hello'), ('2', 'World');

Let’s use the SQLite changes() function to get the number of rows affected by the INSERT statement above:

SELECT changes();
changes()
---------
2

Let’s use the UPDATE statement to change the row whose id is 2:

UPDATE test_changes
SET note = 'Everyone'
WHERE id = 2;

Let’s use the SQLite changes() function to get the number of rows affected by the UPDATE statement above:

SELECT changes();
changes()
---------
1

Finally, let’s delete all rows in the table test_changes using the DELETE statement:

DELETE FROM test_changes;

Let’s use the SQLite changes() function to get the number of rows affected by the DELETE statement above:

SELECT changes();
changes()
---------
2