# ATTACH

ATTACH makes another file-backed or in-memory database available through one embedded connection. Qualify its tables with the namespace, such as `aux.notes`.

## Syntax

```text
ATTACH [DATABASE] 'path' AS namespace
```

## Interface

A server connection rejects ATTACH on both native and HTTP interfaces. Create managed server databases with `CREATE DATABASE` and select them with `USE`.

## 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; CREATE TABLE aux.notes(id INTEGER); INSERT INTO aux.notes VALUES(1);")?;
    let result = db.query("SELECT id FROM aux.notes")?;
    assert_eq!(result.rows[0][0].scalar_text(), "1");
    Ok(())
}
```
