3

At the moment I have apprx. 20 identical structured databases(SQLite) which I transferred from remote destinations (android phones) to my pc. Now I want to add them to a single one in order to perform data analysis on the data. How is this possible? The primary keys of the tables are auto-increment integer , so when using ATTACH I get a Primary key is not unique error. In addition it would be nice if i could somehow keep a reference between the rows and the tables which are coming from.

JustCurious
  • 1,848
  • 3
  • 30
  • 57
  • 2
    possible duplicate: http://stackoverflow.com/questions/80801/how-can-i-merge-many-sqlite-databases – dokkaebi Jan 28 '12 at 21:25
  • I have already read that but does not help me. I have less than 32 databases so ATTACH should be fine. But where do I use ATTACH from? – JustCurious Jan 29 '12 at 19:23
  • @JustCurious [per default, the `SQLITE_MAX_ATTACHED` is `10`](https://www.sqlite.org/limits.html#max_attached), not 32, so the other question provides the way to go. – Wolf Jun 27 '23 at 13:55
  • ... you can inspect the actual limits of your SQLite instance by running `.limit` in the [CLI](https://www.sqlite.org/cli.html). – Wolf Jun 27 '23 at 14:06

1 Answers1

1

The way you worded the question, it sounds to me like it is a one-time operation you're doing on a home PC. I would probably just open a fresh database in the sqlite shell and attach/insert from/detach each database like they show on that link.

If you need to script this, this link has an example of embedding sqlite into shell scripts and this one shows some sql in a dos batch file. More preferably, you could code it up with your favorite language's sqlite bindings, like Python's.

dokkaebi
  • 9,004
  • 3
  • 42
  • 60
  • Since the most important links are dead now, the answer might be not as useful anymore. Do you see any chance to refresh it? – Wolf Jun 27 '23 at 13:57