COPY FROM DATABASE
The COPY FROM DATABASE
statement creates a new database from an existing one. It can be used to:
- Interact with MotherDuck Databases
- Copy MotherDuck databases to MotherDuck databases
- Interact with Local Databases
- Copy local databases to MotherDuck databases
- Copy MotherDuck databases to local databases
- Copy local databases to local databases
Syntax
The COPY FROM DATABASE
statement has the following syntax:
COPY FROM DATABASE <source database name> TO <target database name> [ (SCHEMA) ]
Example usage
Copy a MotherDuck database to a MotherDuck database
This is the same as creating a new database from an existing one.
COPY FROM DATABASE my_db TO my_db_copy;
Interacting with Local Databases
These operations can be done with access to the local filesystem, i.e. inside the DuckDB CLI.
Copy a local database to a MotherDuck database
ATTACH 'md:';
COPY FROM DATABASE local_database.db TO md:md_database;
Copy a MotherDuck database to a local database
To copy a MotherDuck database to a local database requires some extra steps.
ATTACH 'md:';
ATTACH 'local_database.db' as local_db;
COPY FROM DATABASE my_db TO local_db;
Copy a local database to a local database
To copy a local database to a local database, please see the DuckDB documentation.
Copying the Database Schema
COPY FROM DATABASE my_db TO my_db_copy (SCHEMA);
This will copy the schema of the database, but not the data.