w3resource

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.

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

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

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

Here is the result.

Sample Output:

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

Here is the result.

Sample Output:

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

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

Sample Output:

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

Here is the result.

Sample Output:

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.

Sample Output:

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

Here is the result.

Sample Output:

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

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

Previous: abs()
Next: char()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/sqlite/core-functions-changes.php