SQLite Tutorial SQLite Advanced SQLite Database SQLite References

SQLite CHANGES() Function



The SQLite CHANGES() function returns the number of database rows that were changed or inserted or deleted by the most recently completed INSERT, DELETE, or UPDATE statement, exclusive of statements in lower-level triggers.

Syntax

CHANGES()

Parameters

No parameter is required.

Return Value

Returns the number of database rows changed or inserted or deleted by the most recently completed INSERT, DELETE, or UPDATE statement

Example:

Consider the example below, where a table called Employee is created. After creating the table, the CHANGES() function is used to get the number of rows that were changed or inserted or deleted by the most recently completed INSERT, DELETE, or UPDATE statement.

sqlite> CREATE TABLE Employee (
  EmpID INTEGER PRIMARY KEY, 
  Name VARCHAR(50));

sqlite> SELECT CHANGES();
+-----------+
| CHANGES() |
+-----------+
|         0 |
+-----------+

sqlite> INSERT INTO Employee(Name) Values ('John');

sqlite> INSERT INTO Employee(Name) Values ('Marry');

sqlite> SELECT CHANGES();
+-----------+
| CHANGES() |
+-----------+
|         1 |
+-----------+

sqlite> INSERT INTO Employee(Name) Values ('Kim') , ('Jo');

sqlite> SELECT CHANGES();
+-----------+
| CHANGES() |
+-----------+
|         2 |
+-----------+

sqlite> SELECT * FROM Employee;
+-------+-------+
| EmpID | Name  |
+-------+-------+
| 1     | John  |
| 2     | Marry |
| 3     | Kim   |
| 4     | Jo    |
+-------+-------+

sqlite> UPDATE Employee SET Name = 'Suresh' WHERE EmpID = 4;

sqlite> SELECT CHANGES();
+-----------+
| CHANGES() |
+-----------+
|         1 |
+-----------+

sqlite> SELECT * FROM Employee;
+-------+--------+
| EmpID | Name   |
+-------+--------+
| 1     | John   |
| 2     | Marry  |
| 3     | Kim    |
| 4     | Suresh |
+-------+--------+

sqlite> DELETE FROM Employee WHERE EmpID = 4;

sqlite> SELECT CHANGES();
+-----------+
| CHANGES() |
+-----------+
|         1 |
+-----------+

sqlite> SELECT * FROM Employee;
+-------+-------+
| EmpID | Name  |
+-------+-------+
| 1     | John  |
| 2     | Marry |
| 3     | Kim   |
+-------+-------+

❮ SQLite Functions