liveBook · Manning

Use statement

As explained in DuckDB in Action

A USE statement selects the current database for subsequent SQL operations in a session.

A USE statement switches the current database for the session. After switching, queries can refer to tables without repeating the database prefix. section 7.3.1

Switch, then query

After attaching the remote countries database, run `USE countries;`, then query `FROM cities;`. The unqualified table name resolves in the selected database. You can verify the active database with `SELECT current_database();`. section 7.3.1 section 7.3.2

Creating a database does not select it automatically. Switch to the intended database before creating tables or querying data; switch away before dropping it. section 7.3.2

USE countries;  #1
FROM cities;

Shows the compact workflow: select countries, then query cities without a database prefix. section 7.3.1

How DuckDB in Action covers it

How deep it goes
Explains switching, verification, qualification, and cleanup, but does not descend into session internals.
Examples
Uses countries.cities and my-test.people to demonstrate unqualified queries, verification, counting, and cleanup.
What it assumes
Assumes an attached or created database and basic SQL querying; teaches database selection from the session workflow.
What you can do after
Operate/configure a DuckDB or MotherDuck session by selecting databases and checking the active context.
How it connects
Connects database selection with table qualification, CREATE DATABASE, current_database, and DROP DATABASE.

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.