---
sidebar_position: 1
title: DETACH
description: Detach local, remote, or shared databases from your session
---
# DETACH

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.
