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

Drop Table

Function

Drop a table. DROP TABLE is used to drop an existing table and its metadata.

  • OBS table (external table): Only metadata information is deleted. The data stored on OBS is not deleted.
  • Management table: Both data and corresponding metadata information are deleted.

Syntax

DROP TABLE [ IF EXISTS ] [ db_name. ] table_name

Keywords

IF EXISTS: If specified, no error is reported when the table does not exist. If not specified and the table does not exist, an exception is thrown.

Parameters

Parameter

Mandatory

Description

db_name

No

Database name. If not specified, the current database is used by default. Naming rule: Only letters, digits, and underscores (_) are allowed. Cannot be purely numeric and cannot start with a digit or underscore.

table_name

Yes

Name of the table to be dropped.

Precautions

  • The table to be dropped must exist in the current database. Otherwise, an error will occur. Adding IF EXISTS can prevent the error.
  • For OBS tables (external tables), DROP TABLE only deletes metadata. The data files under the OBS path are retained. For managed tables, both metadata and data are deleted.

Example 1: Drop Table

Drop the table named employee in the current database.

DROP TABLE employee;

Example 2: Use IF EXISTS to Avoid Errors

Drop the table named employee. If the table does not exist, no error is reported.

DROP TABLE IF EXISTS employee;

Example 3: Drop a Table in a Specified Database

Drop the table named employee in the company_db database.

DROP TABLE IF EXISTS company_db.employee;

Example 4: Difference Between OBS Table and Managed Table

The following example demonstrates the behavioral difference when dropping an OBS table versus a managed table.

-- Drop a managed table: Both metadata and data are deleted.
DROP TABLE IF EXISTS managed_table;

-- Drop an OBS table (external table): Only metadata is deleted. Data files on OBS are retained.
DROP TABLE IF EXISTS obs_table;

To clean up the data files corresponding to an OBS table, manually delete the files under the OBS path, for example, obs://bucket-name/path/to/data/.