Skip to content

DETACH ​

DETACH removes an attached namespace from an embedded connection. It does not delete the database file. An attachment used by an active transaction cannot be detached.

Syntax ​

text
DETACH [DATABASE] namespace

Interface ​

Native and HTTP server connections reject DETACH. This command operates on embedded connection namespaces, rather than the managed server database inventory.

Example ​

Using the embedded Connection API ​

The following application uses an in-memory attachment, so it does not require an existing database file:

rust
use coordinator::Connection;

fn main() -> coordinator::Result<()> {
    let mut db = Connection::open_in_memory()?;
    db.execute("ATTACH ':memory:' AS aux; DETACH aux;")?;
    let result = db.query("PRAGMA database_list")?;
    assert!(result.rows.iter().all(|row| row[1].scalar_text() != "aux"));
    Ok(())
}