changes
SQLite 3.x+→ INTEGERReturns the number of database rows that were changed, inserted, or deleted by the most recently completed INSERT, DELETE, or UPDATE statement, exclusive of statements in lower-level triggers. This is a wrapper around the sqlite3_changes64() C/C++ function.
Signature
changes()Examples
One row was inserted
INSERT INTO employees(name) VALUES('Alice');
SELECT changes();1Returns count of rows affected by the UPDATE
UPDATE employees SET dept = 'Engineering' WHERE active = 1;
SELECT changes();42Rows deleted by the DELETE
DELETE FROM logs WHERE created_at < date('now','-30 days');
SELECT changes();150No DML has run yet in this connection
SELECT changes();0Multi-row insert counts all inserted rows
INSERT INTO t(x) VALUES(1),(2),(3);
SELECT changes();3Calling changes() after a series of DML statements and summing the results — or reading it once after several operations — gives you only the count from the last statement. Each call overwrites the previous result, so intermediate counts are silently lost.
✓ Instead: Use total_changes() and subtract a baseline captured before the batch to get the cumulative count for all statements in the group.
changes() only counts rows modified by the immediately-preceding top-level statement. Rows changed inside triggers are NOT counted. Use total_changes() if you need a running total across the entire session.
SQLite-specific function. Equivalent to sqlite3_changes64() in the C API. Not available in PostgreSQL or other SQL engines.