Skip to contents

Drops an existing schema (if it exists) in the specified database and then creates a new empty schema. If the connection is to a MotherDuck instance, the function switches to the given database first, then drops and recreates the schema. Displays helpful CLI output about the current connection, user, and database.

Usage

delete_and_create_schema(.con, database_name, schema_name)

Arguments

.con

A valid DBI connection (DuckDB / MotherDuck).

database_name

The name of the database where the schema should be dropped and recreated.

schema_name

The name of the schema to drop and recreate.

Value

Invisibly returns NULL. Side effect: drops and recreates the schema and prints CLI status messages.

Details

  • Executes DROP SCHEMA IF EXISTS ... CASCADE to remove an existing schema and all contained objects.

  • Executes CREATE SCHEMA IF NOT EXISTS to recreate it.

  • If connected to MotherDuck (detected by validate_md_connection_status()), performs a USE <database> first.

  • Prints a summary of the current connection and schema creation status using internal CLI helpers.