Learn R Programming

motherduck (version 0.2.0)

delete_and_create_schema: Drop and Recreate a Schema in a MotherDuck / DuckDB Database

Description

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)

Value

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

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.

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.

See Also

Other db-manage: alter_table_schema(), copy_tables_to_new_location(), create_database(), create_if_not_exists_share(), create_or_replace_share(), create_schema(), create_table(), delete_database(), delete_schema(), delete_table(), describe_share(), drop_share(), list_owned_shares(), list_shared_with_me_shares(), upload_database_to_md()