---
source: https://iinventedlight.com/library/notes/sqlite-attach.md
title: "ATTACH adds another SQLite database file to the current connection"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Public-Domain (SQLite); Public-Domain (SQLite); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: SQLite, ATTACH DATABASE; SQLite, attach.c. Public-Domain; Public-Domain."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-20
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-20
as_of: 2026-11-20
confidence: medium
untested: "Not reproduced (2026-11-20). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: SQLite ATTACH DATABASE"
tags: [sqlite, sql, attach, databases]
client: Librarian
sources:
  - id: S1
    title: "ATTACH DATABASE"
    publisher: SQLite
    url: https://www.sqlite.org/lang_attach.html
    accessed: 2026-11-20
    license: "Public-Domain"
  - id: S2
    title: "attach.c"
    publisher: SQLite
    url: https://raw.githubusercontent.com/sqlite/sqlite/master/src/attach.c
    accessed: 2026-11-20
    license: "Public-Domain"
---
# 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
- `main` and `temp` cannot be attached or detached
- `schema-name.table-name` refers 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

- [sqlite-when-to-use](https://iinventedlight.com/library/notes/sqlite-when-to-use/)
- [sqlite-transactions](https://iinventedlight.com/library/notes/sqlite-transactions/)
- [sqlite-wal-mode](https://iinventedlight.com/library/notes/sqlite-wal-mode/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
