Andy Band
Andy Band

Reputation: 313

SQLite - How join data from multi database and query

I have this scenario: one database in the app and many database that are downloaded from different devices and saved in the same database folder:

mydatabase.db           // database of app
device1_mydatabase.db   // database from device 1
device2_mydatabase.db    // database from device 2
device3_mydatabase.db    // database from device 3
....
... 

All databases have the same structure , because are the same app in different devices. I have one query that obtain the total production from the mydatabase.db. I would like to obtain a total query from all databases.

1) is better to create a new database copy and insert all data from the single database and then query the total or there are different better approach?

Upvotes: 0

Views: 52

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269443

This may be a matter of opinion, but I think it is better to load the data into a single database. This gives more control for the application. Here are four reasons that come to mind:

  1. You can optimize the database for the queries that you want to run (say by changing indexes or restructuring tables).
  2. You can incrementally load the tables into the master database as they become available.
  3. Adding another device does not require changing the final queries that are run (just the loading code).
  4. If you change the underlying database structure, then you will have an issue where the databases are not identical. Having a layer in-between isolates the final queries from the original databases.

Upvotes: 1

Related Questions