liveBook · Manning

Create database statement

As explained in DuckDB in Action

A CREATE DATABASE statement is a database command that creates a named database.

CREATE DATABASE creates a named database in MotherDuck. It does not switch the current session, so run USE afterward or qualify table names with the database name. section 7.3.2

Create, select, and verify a database

CREATE DATABASE "my-test"; SHOW DATABASES; USE my-test; SELECT current_database(); CREATE TABLE people (name varchar, born date); INSERT INTO people VALUES ('Mark', '1989-01-01'), ('Hannes', '1990-01-01'); SELECT count(*) FROM people; section 7.3.2

Use the statement in two practical workflows:

  • Create a cloud database directly when source files already reside in public cloud storage, avoiding a local download and re-upload. section 7.3.2
  • Upload an existing local DuckDB database with CREATE DATABASE "countries" FROM 'countries.duckdb'; then detach or switch before sharing. section 7.3.1
  • Inspect databases with SHOW DATABASES or .databases, and remove a test database after switching away from it with USE and DROP DATABASE. section 7.3.2
.open md:
CREATE DATABASE "countries" FROM 'countries.duckdb';

Shows the CLI sequence for attaching MotherDuck and creating a database from a local DuckDB file. section 7.3.1

How DuckDB in Action covers it

How deep it goes
Explains creation, session selection, inspection, table use, and deletion, but does not develop database internals.
Examples
Demonstrates my-test and countries databases, people and cities tables, local upload, row counts, and session verification.
What it assumes
Assumes access to DuckDB and MotherDuck, while teaching the creation-to-query session workflow from command examples.
What you can do after
Operate MotherDuck through the DuckDB CLI by creating, selecting, querying, inspecting, uploading, and removing databases.
How it connects
Connects CREATE DATABASE with USE, SHOW DATABASES, current_database, DROP DATABASE, and database-qualified table names.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of DuckDB in Action. The section links point to the parts of the book it draws on.