SQLite TOTAL_CHANGES() Function
The SQLite TOTAL_CHANGES() function returns the number of row changes caused by INSERT, UPDATE or DELETE statements since the current database connection was opened.
Syntax
TOTAL_CHANGES()
Parameters
No parameter is required.
Return Value
Returns the number of row changed caused by INSERT, UPDATE or DELETE in the database for the current session
Example:
Consider the example below, where a table called Employee is created. After creating the table, the TOTAL_CHANGES() function is used to get the number of row changed due to using INSERT, UPDATE or DELETE statements in the database for the current session.
sqlite> CREATE TABLE Employee ( EmpID INTEGER PRIMARY KEY, Name VARCHAR(50)); sqlite> SELECT TOTAL_CHANGES(); +-----------------+ | TOTAL_CHANGES() | +-----------------+ | 0 | +-----------------+ sqlite> INSERT INTO Employee(Name) Values ('John'); sqlite> INSERT INTO Employee(Name) Values ('Marry'); sqlite> SELECT TOTAL_CHANGES(); +-----------------+ | TOTAL_CHANGES() | +-----------------+ | 2 | +-----------------+ sqlite> INSERT INTO Employee(Name) Values ('Kim') , ('Jo'); sqlite> SELECT TOTAL_CHANGES(); +-----------------+ | TOTAL_CHANGES() | +-----------------+ | 4 | +-----------------+ 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 TOTAL_CHANGES(); +-----------------+ | TOTAL_CHANGES() | +-----------------+ | 5 | +-----------------+ sqlite> SELECT * FROM Employee; +-------+--------+ | EmpID | Name | +-------+--------+ | 1 | John | | 2 | Marry | | 3 | Kim | | 4 | Suresh | +-------+--------+ sqlite> DELETE FROM Employee WHERE EmpID = 4; sqlite> SELECT TOTAL_CHANGES(); +-----------------+ | TOTAL_CHANGES() | +-----------------+ | 6 | +-----------------+ sqlite> SELECT * FROM Employee; +-------+-------+ | EmpID | Name | +-------+-------+ | 1 | John | | 2 | Marry | | 3 | Kim | +-------+-------+
❮ SQLite Functions