Skip to main content

ATTACH DATABASE

The ATTACH DATABASE statement adds another database file to the current connection under a schema name. Once attached, tables in the external database can be queried alongside tables in the main database.

Syntax

Description

ATTACH opens the database file at filename and makes its tables accessible through the given schema-name. Tables in the attached database are referenced as schema-name.table-name.

Clauses

Every connection has a built-in schema named main for its primary database. The names main and temp are reserved and cannot be used as schema names for attached databases.
This feature is experimental and must be enabled before use. Attached databases support both read and write operations (INSERT, UPDATE, DELETE, CREATE TABLE, etc.). The attached database’s journal mode must match the main database’s journal mode (e.g., both WAL or both MVCC).

Examples

Attach and Query an External Database

Cross-Database Queries

Attach an In-Memory Database

See Also