← All notes

ATTACH adds another SQLite database file to the current connection

Answer: The ATTACH DATABASE statement adds another database file to the current database connection. Files that were previously attached can be removed using the DETACH DATABASE command.

Filenames and schema names

The filename of the database being attached is the expression before the AS keyword. The identifier after AS is the internal name SQLite uses for that database. URI filenames work only when URI filename processing is enabled; it is disabled by default. An attached database uses the same VFS as the main database, unless the vfs=NAME URI flag names another VFS. When two or more tables in different databases share a name and no schema-name prefix is given, SQLite picks the table from the database that was least recently attached.

Transactions, limits, and parsing

Multi-database transactions are atomic if the main database is not :memory: and journal_mode is not WAL. If the main database is :memory:, or journal_mode is WAL, atomicity still holds inside each individual database file. A crash of the host computer in the middle of a COMMIT that updates two or more database files can leave some files changed and others not. There is a limit, set using sqlite3_limit() and SQLITE_LIMIT_ATTACHED. In the implementation, simple identifiers are treated as strings, not possible column names or aliases.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: SQLite, ATTACH DATABASE; SQLite, attach.c. Public-Domain; Public-Domain. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: SQLite, ATTACH DATABASE; SQLite, attach.c. Public-Domain; Public-Domain.

Cite this

Permanent ID: iil:note:mnq0r2j4

iinventedlight. 2026. "ATTACH adds another SQLite database file to the current connection." iinventedlight Library, iil:note:mnq0r2j4, version of 2026-11-20. https://iinventedlight.com/library/notes/sqlite-attach/. License: CC-BY-4.0.

@misc{iil_note_mnq0r2j4,
  author = {{iinventedlight}},
  title = {{ATTACH adds another SQLite database file to the current connection}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-20},
  url = {https://iinventedlight.com/library/notes/sqlite-attach/},
  note = {Permanent ID iil:note:mnq0r2j4. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/sqlite-attach.md.