Skip to main content

The CREATE DATABASE statement creates a new database in MotherDuck. It can be used to either copy entire databases into MotherDuck from your local environment, or to zero-copy clone databases inside of MotherDuck.

CREATE DATABASE <database_name> FROM enables you to:

  • create a remote database (on MotherDuck) from a local database.
  • create a remote database (on MotherDuck) from a remote database.. This is a metadata-only operation that copies no data.
info

CREATE DATABASE <database_name> FROM a mounted share is not supported at the moment.

Syntax

This SQL query creates a new database in MotherDuck.

CREATE [ OR REPLACE | IF NOT EXISTS ] DATABASE <database name> [FROM CURRENT_DATABASE() | FROM <database name> | FROM '<local/file/path.db>' ];

If you attempt to create a database, yet a database with that name already exists, no new database will be created and the query will return an error. The error will be silenced when you specify IF NOT EXISTS.

Similar to the 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 automatically make it your current database: execute the SQL command USE DATABASE <database name> to do so.

Example usage

CREATE OR REPLACE DATABASE ducks;     -- if ducks database exists, even if populated, it will be replaced with an empty one
CREATE DATABASE IF NOT EXISTS ducks_db; -- if ducks_db database exists, the operation will be skipped, but will not error

To copy an entire database from your local DuckDB instance into MotherDuck:

USE ducks_db;
CREATE DATABASE ducks FROM CURRENT_DATABASE();
CREATE OR REPLACE DATABASE ducks FROM ducks_db; -- alternative syntax

To zero-copy clone a database 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';