How to join records from a table distributed in multiple .sqlite files?

2

I have several files with .sqlite extension, each containing at least 1000 records totaling about 4,000 records. See how they are distributed:

  • vihicles1.sqlite
  • vihicles2.sqlite
  • vihicles3.sqlite
  • vihicles4.sqlite

Inside each file has a single table with the name tblVehicle that contains the following columns:

  • id (integer)
  • make (text)
  • model (text)
  • year (int)

I'm using SQLiteStudio for database management. Is it possible to merge these files by creating only 1 file with all the records?

    
asked by anonymous 20.02.2017 / 17:44

1 answer

3

Attach the files to the session, give INSERT by selecting the table data in each database. The base name (last name of the table) comes before the table.

ATTACH 'path/aqui/vihicles1.sqlite' as v1;         
ATTACH 'path/aqui/vihicles2.sqlite' as v2;
ATTACH 'path/aqui/vihicles3.sqlite' as v3;
ATTACH 'path/aqui/vihicles4.sqlite' as v4;

INSERT INTO tblVehicle SELECT * FROM v1.tblVehicle;
INSERT INTO tblVehicle SELECT * FROM v2.tblVehicle;
INSERT INTO tblVehicle SELECT * FROM v3.tblVehicle;
INSERT INTO tblVehicle SELECT * FROM v4.tblVehicle;

DETACH 'path/aqui/vihicles1.sqlite';
DETACH 'path/aqui/vihicles2.sqlite';
DETACH 'path/aqui/vihicles3.sqlite';
DETACH 'path/aqui/vihicles4.sqlite';

Do not think this case is much needed at low volume, but some settings may be useful for improving performance:

Some examples that might help:

PRAGMA synchronous = OFF
PRAGMA journal_mode = MEMORY

This does not create indexes.

You can use one of the files to receive the others, then the indexes already exist. But the import may be much slower. I do not know how to optimize SQLite, but it was faster to import without index and then create index.

It would be good to test some situations and see how it works best for you.

    
20.02.2017 / 17:46