Skip to main content

DETACH <database>

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

DETACH <database name>;

Example usage

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

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