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
:memory:results in an in-memory database- empty string results in a new temporary database
mainandtempcannot be attached or detachedschema-name.table-namerefers to a table in an attached database
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
- id: C1 claim: ATTACH DATABASE adds another database file to the current connection; DETACH removes one that was attached. source: S1 evidence: "The ATTACH DATABASE statement adds another database file to the current"
- id: C2 claim: The special name :memory: opens an in-memory database; an empty string opens a new temporary database. source: S1 evidence: "special name \" :memory: \" results in an in-memory database"
- id: C3 claim: In ATTACH, simple identifiers are treated as strings, not column names. source: S2 evidence: "identifiers are treated as strings, not possible column names or aliases."
Sources
- [S1] ATTACH DATABASE. SQLite. https://www.sqlite.org/lang_attach.html . License: Public-Domain. Accessed 2026-11-20.
- [S2] attach.c. SQLite. https://raw.githubusercontent.com/sqlite/sqlite/master/src/attach.c . License: Public-Domain. Accessed 2026-11-20.
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
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.},
}
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.
- sqlite-attach.table.json (table; CC-BY-4.0)
- sqlite-attach.schema.json (schema; CC-BY-4.0)
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.