Drop and Recreate a Schema in a MotherDuck / DuckDB Database
Source: R/utils-db.R
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
Value
Invisibly returns NULL. Side effect: drops and recreates the schema and prints CLI status messages.
Details
-
Executes
DROP SCHEMA IF EXISTS … CASCADEto remove an existing schema and all contained objects. -
Executes
CREATE SCHEMA IF NOT EXISTSto recreate it. -
If connected to MotherDuck (detected by
validate_md_connection_status()), performs aUSE <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()