Updated on 2026-11-06 GMT+08:00

DROP Statements

Overview

DROP statements are used to delete registered objects from a catalog, including tables, databases, views, functions, and catalogs. The deletion operation removes the metadata definition of the object. For some connectors (such as Hive), the underlying physical data is also deleted.

Application Scenarios

  • Resource cleanup: Deletes tables, views, or databases that are no longer used to release metadata and storage resources.
  • Environment reset: Deletes temporary objects during development or testing to restore the initial status.
  • Function management: Deregisters custom functions that are no longer used to avoid naming conflicts.

Notes and Constraints

  • DROP TABLE deletes only metadata. Whether to delete physical data depends on the connector implementation. HiveCatalog deletes both physical data and metadata by default, while other connectors may only delete metadata.
  • By default, DROP DATABASE uses the RESTRICT mode. If the database is not empty, an exception is thrown. You can use CASCADE to delete all objects in the database in cascading mode.
  • Deleting a table or view that is being used by a job may cause job exceptions. You are advised to perform this operation after the job is stopped.
  • DROP CATALOG only removes the catalog registration information in the session and does not affect the data in the external metastore.
  • After a function is deleted using DROP FUNCTION, the SQL query that references the function cannot be executed.

Syntax Structure

DROP TABLE

DROP TABLE [IF EXISTS] [catalog_name.][db_name.]table_name;

DROP DATABASE

DROP DATABASE [IF EXISTS] [catalog_name.]db_name [ (RESTRICT | CASCADE) ];

DROP VIEW

DROP VIEW [IF EXISTS] [catalog_name.][db_name.]view_name;

DROP FUNCTION

DROP [SYSTEM] FUNCTION [IF EXISTS] [catalog_name.][db_name.]function_name;

DROP CATALOG

DROP CATALOG [IF EXISTS] catalog_name;

Syntax Description

Parameter

Mandatory

Description

IF EXISTS

No

Specifies that no error is reported when the object does not exist. If this parameter is not specified and the object does not exist, an exception is thrown. You are advised to always use this parameter to avoid script interruption.

RESTRICT

No

Specifies the default mode of DROP DATABASE. If the database is not empty, an exception is thrown to prevent the database containing objects from being deleted by mistake.

CASCADE

No

Cascades the deletion of all tables, views, and functions in the database. Exercise caution when using this parameter and ensure that the deletion scope is correct.

SYSTEM

No

Deletes a system function. The system function is parsed with a higher priority than the built-in function. After the system function is deleted, the default behavior of the built-in function is restored.

Usage Example

Example: DROP TABLE and DROP DATABASE

-- DROP TABLE IF EXISTS my_table;
-- DROP DATABASE IF EXISTS my_db CASCADE;
-- DROP VIEW IF EXISTS my_view;
-- DROP FUNCTION IF EXISTS my_udf;