Multiple files for a single SQLite database

I found out, that it is possible.

Use:

sqlite3.exe MainDB.db

ATTACH DATABASE 'SomeTableFile.db' AS stf;

Access the table from the other database file:

SELECT * FROM stf.SomeTable;

You can even join over several files:

SELECT *
FROM MainTable mt
JOIN stf.SomeTable st
ON (mt.id = st.mt_id);

https://www.sqlite.org/lang_attach.html

tameera said there is a limit of 62 attached databases but I never hit that limit so I can’t confirm that.

The big advantage besides some special cases is that you limit the fragmentation in the database files and you can use the VACUUM command separately on each table!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)