I would like to compare 2 SQLite databases in order to check whether it needs to be updated on the client computer.

I am not really sure how I should do this. Whether I should make an internal version ID or compare the file size (which probally is not a good idea because I think the file size doesn't change anytime I edit the database).

Does anybody know a good way to do what I need to do?

Thank you!

asked May 12, 2016 at 19:27

Maiken Roskilde's user avatar

2

You might try dumping each SQLite database, using SQLite's .dump command:

$ sqlite3 /path/to/database1 .dump > database1.sql
$ sqlite3 /path/to/database2 .dump > database2.sql

And then comparing the generated files. If your two databases are quite similar, a simple diff might work to show any differences, e.g.:

$ diff -u database1.sql database2.sql

Hope this helps!

answered May 12, 2016 at 20:11

Castaglia's user avatar

CastagliaCastaglia

3,0795 gold badges30 silver badges50 bronze badges

3

A bit late for original question but may be will be helpful for others.

On Windows you can use KS DB Merge Tools for SQLite. I am the author of this tool. Compares both DB object definitions and data. Free version available and pretty functional for diff/compare needs.

EDIT 2022-06-29 I've made the web wasm-based diff-only version of this tool: https://ksdbmerge.tools/for-sqlite-online

EDIT 2022-02-21: Accepted .dump answer is good for many cases, but it can report false-positive changes. Here is dump result for this question: enter image description here Both columns are part of the primary key, so from the point of data model data is the same but dumps are different. My tool is using primary key to compare data so no changes would be reported for such case.

answered Dec 14, 2020 at 18:45

sarh's user avatar

sarhsarh

6,5774 gold badges26 silver badges34 bronze badges

1

You could use sqldiff.

On Debian or Debian-based systems (and possibly other Linux systems) it is installed by default when installing sqlite3: apt install sqlite3

On MacOS, it can be installed with Homebrew : brew install sqldiff

answered Dec 11, 2020 at 18:36

mivk's user avatar

mivkmivk

14.7k5 gold badges83 silver badges74 bronze badges