CREATE DATABASE
The CREATE DATABASE
statement creates a new MotherDuck database. You can also use it to:
- Create a MotherDuck database from a local DuckDB database.
- Create a MotherDuck database from another MotherDuck database or share via zero-copy clone (without physically copying data).
To copy a MotherDuck database to a local database, use the COPY FROM DATABASE
statement.
When the source is another MotherDuck database or a share, CREATE DATABASE ... FROM
performs a zero-copy clone. The command completes almost instantly because no data is physically duplicated. When the source is a local file, data is physically copied to MotherDuck.
Syntax
CREATE [ OR REPLACE ] DATABASE [ IF NOT EXISTS ] <database name>
-- If the source is left empty, the database will be created
-- using the current database in use as source.
[
FROM <database name> |
FROM '<local/file/path.db>' |
FROM 'md:_share/...' |
FROM CURRENT_DATABASE() -- Important: this command does not work with attached shares
];
You can also pass the name of an attached share or a share URL as the database name, for example CREATE DATABASE FROM my_share
or CREATE DATABASE FROM 'md:_share/...'
.
If the database name already exists, the statement returns an error unless you specify IF NOT EXISTS
.
Similar to DuckDB table name conventions, database names that start with a number or contain special characters must be double-quoted when used. Example: CREATE DATABASE "123db"
Creating a database does not change the active database. Run USE DATABASE <database name>
to switch.
Example Usage
CREATE OR REPLACE DATABASE ducks; -- if ducks exists, it will be replaced with an empty database
CREATE DATABASE IF NOT EXISTS ducks_db; -- no-op if ducks_db already exists
To copy an entire database from your local DuckDB instance into MotherDuck:
USE ducks_db;
CREATE DATABASE ducks FROM CURRENT_DATABASE();
-- Or alternatively:
CREATE OR REPLACE DATABASE ducks FROM ducks_db;
To zero-copy clone a database that is already attached in MotherDuck:
CREATE DATABASE cloud_db FROM another_cloud_db;
To upload a local DuckDB database file:
CREATE DATABASE flying_ducks FROM './databases/local_ducks.db';
To upload an attached local DuckDB database:
ATTACH './databases/local_ducks.db';
CREATE DATABASE flying_ducks FROM local_ducks;