Livestream: Ducklake & The Future of Open Table Formats - June 17Register Now

Skip to main content

DETACH

The DETACH command in MotherDuck can be used to:

  • Detach a local DuckDB database
  • Detach a remote MotherDuck database
  • Detach a shared database

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

Syntax for Databases

DETACH <database name>;

Examples of Database Detachment

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

DETACH <shared database name>;

Examples of Share Detachment

DETACH ducks;

For more information, see the Attach & Detach guide.