SQLite allows to attach external SQLite databases (i.e. other database files) to a currently connected database. Using such a feature, it is possible to manipulate the data from different databases inside one connection, e.g. writing heterogeneous SQL queries like joins, unions etc. Please note that attaching external databases does not mean physically merging the corresponding files, this is just linking them to access the data.

Database Tour application supports this possibility. But there are some things you need to know in order to use this opportunity correctly and effectively.

Attaching a database

After connecting to a SQLite database, it is possible to attach another database to it. Currently, this must be done by SQL. So, create a new SQL window by clicking New SQL Window button , choosing Query | New... menu, or pressing Ctrl+Q. Then write and execute the command like this:

ATTACH DATABASE "C:\data sources\sales.db" AS sales;

Here, you specify the path to the database file to attach and the alias for the attached database. You will need that alias to access the tables from the attached database.

Notes

Working with attached databases

After attaching a database and clicking Refresh button above the table list, you will able to see tables from the attached database there; the table names will be prefixed with the attached database alias followed by a period. Clicking such a table will open it in a separate Table window just like it is done for all other tables of the open database. Note: All that will be possible only if you turned off the Asynchronous query execution option (see the notes above).

There will be possible to join the tables from different databases in one SQL command, for example:

SELECT
  o.order_date,
  c.client_name,
  o.order_sum,
  o.order_vat,
  o.notes
FROM clients c
  JOIN [sales].orders o ON o.client_id = c.client_id
ORDER BY 1, 2;

The results of such combined queries can be exported, used in reports etc.

It will be also possible to insert, update, or delete records in tables of the attached database as well as create or delete table etc.

Detaching a database

To detach an attached database, execute the SQL command like this:

DETACH DATABASE sales;

Here, you must specify the alias of the attached database.

Notes

See also