Skip to content
Blog

Drop

Dropping a table removes the table and all its data from the database.

For example, consider the following database:

CREATE NODE TABLE User(name STRING, age INT64, reg_date DATE, PRIMARY KEY (name));
CREATE REL TABLE Follows(FROM User TO User, since DATE);

Directly dropping the User node table will fail.

DROP TABLE User
Binder exception: Cannot delete a node table with edges. It is on the edges of rel: Follows.

You can first delete the Follows rel table, and subsequently the User table as follows:

DROP TABLE Follows
---------------------------------------
| RelTable: Follows has been dropped. |
---------------------------------------
DROP TABLE User
-------------------------------------
| NodeTable: User has been dropped. |
-------------------------------------

IF EXISTS

If the given table does not exist in the database, Kùzu throws an exception when you try to drop it. To avoid the exception being raised, use the IF EXISTS clause. This instructs Kùzu to do nothing when the given table name does not exist in the database.

Example:

DROP TABLE IF EXISTS UW

This query tells Kùzu to drop the UW table only if it exists.