DROP DATABASE) Delete a database.
Syntax
DROP DATABASE [IF EXISTS] [databaseIdentifier]
Example
-- create database CREATE DATABASE example_db -- delete database DROP DATABASE example_db
DROP TABLE) Delete a table.
Syntax
DROP TABLE [IF EXISTS] [tableIdentifier]
Example
-- 1. create table CREATE TABLE `example_table` ( `order_by_column` String ) ENGINE = `CnchMergeTree` ORDER BY (`order_by_column`) -- 2. delete table DROP TABLE example_table
DROP VIEW) Delete a view. Views can also be deleted using the DROP TABLE command, but DROP VIEW checks whether [db.]name is a view.
Syntax
DROP VIEW [IF EXISTS] [db.]name
DROP DICTIONARY) Delete a dictionary.
Syntax
DROP DICTIONARY [IF EXISTS] [db.]name
Remove all data in a table.
warning
Data deleted by the TRUNCATE operation cannot be restored. Please operate with caution.
Syntax
TRUNCATE TABLE [IF EXISTS] [tableIdentifier]
Example
TRUNCATE TABLE IF EXISTS example_table
If you mistakenly delete a table using DROP TABLE, you can restore it with UNDROP TABLE. This method is only applicable for restoring deletions performed by DROP TABLE, and the validity period is limited. Currently, you can restore tables deleted within the past two days at most, which can be used for temporary loss prevention due to accidental operations. It is strongly recommended to use the backup restore function. For details, see backup restore.
Examples are as follows:
# Delete table, but discover the table was mistakenly deleted DROP TABLE db_name.table_name; # Use UNDROP TABLE to restore the table UNDROP TABLE db_name.table_name; # Query data to verify whether the restoration was successful SELECT count() FROM db_name.table_name;