SQLite changes

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

SQLite changes() function

Description

The 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. The changes() SQL function is a wrapper around the sqlite3_changes() C/C++ function and hence follows the same rules for counting changes.

Syntax

changes()

Example : MySQL AVG() function

Example : SQLite changes() function

The following SQLite statement will create a table tables1.

  1. sqlite> CREATE TABLE table1(x INTEGER PRIMARY KEY, y);  

Let insert some records into table1 and see the changes with change() function.

  1. sqlite> INSERT INTO table1 VALUES(1, 'AAA');  

Here is the result.

sqlite> SELECT changes();
changes()
----------
1
  1. sqlite> INSERT INTO table1 VALUES(2, 'BBB');  

Here is the result.

sqlite> SELECT changes();
changes()
----------
1

Let update some records into table1 and see the changes with change() function.

sqlite> SELECT * FROM table1;
x           y
----------  ----------
1           AAA
2           BBB
  1. sqlite> UPDATE table1 SET y='DDD';  

Here is the result.

sqlite> SELECT changes();
changes()
----------
2

sqlite> SELECT * FROM table1;
x           y
----------  ----------
1           DDD
2           DDD

Let delete the first record (where x =1) from the table table1 and see the changes with change() function.

sqlite> SELECT * FROM table1;
x           y
----------  ----------
1           DDD
2           DDD
  1. sqlite> DELETE FROM table1 WHERE x=1;  

Here is the result.

sqlite> SELECT changes();
changes()
----------
1

sqlite> SELECT * FROM table1;
x           y
----------  ----------
2           DDD