Skip to content

Attaching and Detaching databases

Attaching a database adds a second (or third, or fourth…) database to an existing connection, so you can query across all of them at once — for example, to copy rows from a table in one database into a table in another with a single INSERT ... SELECT. Each attached database keeps its own alias, and its tables and views appear in the tree panel prefixed with that alias.

You can attach and detach databases from the menu, or with the SQLite ATTACH and DETACH commands.

Attaching a database

  1. Select the database you want to attach to in the tree panel.
  2. Choose File → Attach Database from the main menu.
  3. Select the database file and give it an alias.

Once attached, its objects appear in the tree under the connection, each prefixed with the alias (for example backup.customer). You can then reference them in SQL:

-- copy new customers from an attached 'backup' database into the main one
INSERT INTO customer
SELECT * FROM backup.customer
WHERE CustNo NOT IN (SELECT CustNo FROM customer);

Tip

You can also attach a database by dragging its file from Windows Explorer onto the tree panel while holding Shift. Without Shift, the file is opened as a separate database instead.

Detaching a database

  1. Choose File → Detach Database from the main menu.
  2. Select the database to detach from the list of attached databases.

SQLite Expert remembers which databases were attached and reattaches them automatically the next time you start the program.

See also: Opening an existing database · Displaying database information and internal parameters