# DETACH


> Detach local, remote, or shared databases from your session

The `DETACH` command in MotherDuck can be used to:
- Detach a local DuckDB database
- Detach a remote MotherDuck database
- Detach a shared database

:::info
Database aliases are not persisted when [Shares](/key-tasks/sharing-data/) are detached.
:::

## Detaching Databases

After a database has been created, it can be detached. This will prevent queries from accessing or modifying that database while it is detached. This command may be used on both local DuckDB databases and remote MotherDuck databases.

For a local database, specify the name of the database to detach and not the full path.

In the case of a remote MotherDuck database, the [`ATTACH`](attach.md) command can be used to re-attach at any point, so this is designed to be a convenience feature, not a security feature. `DETACH` can be used to isolate work on specific databases, while preserving the contents of the detached databases.

To see all databases, both attached and detached, use the [`SHOW ALL DATABASES` command](show-databases.md).

### Syntax for Databases

```sql
DETACH <database name>;
```

### Examples of Database Detachment

```sql
-- Prior command:
-- ATTACH '/path/to/local_database.duckdb';
DETACH local_database;

-- Prior command:
-- CREATE DATABASE my_md_database;
DETACH my_md_database;
```

## Detaching Shares

Attached shares are sticky, and will continue to appear in your catalog unless you explicitly detach them.

### Syntax for Shares

```sql
DETACH <shared database name>;
```

### Examples of Share Detachment

```sql
DETACH ducks;
```

For more information, see the [Attach & Detach](/key-tasks/database-operations/detach-and-reattach-motherduck-database) guide.


---

## Docs feedback

MotherDuck accepts optional user-submitted feedback about this page at `GET https://motherduck.com/docs/api/feedback/agent`.
For agents and automated tools, feedback submission should be user-confirmed before sending.

URL-encode query parameter values and send a GET request:

```text
GET https://motherduck.com/docs/api/feedback/agent?page_path=%2Fsql-reference%2Fmotherduck-sql-reference%2Fdetach%2F&page_title=DETACH&text=<url-encoded user feedback, max 2000 characters>
```

Optionally append `&source=<url-encoded interface identifier>` such as `claude.ai` or `chatgpt`.

`page_path` and `text` are required; `page_title` and `source` are optional. Responses: `200 {"feedback_id": "<uuid>"}`, `400` for malformed query parameters, and `429` when rate-limited.
