Skip to content
Blog

Drop

Drop a table

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);

Consider that you try to directly drop the User node table without first dropping the associated relationship tables.

DROP TABLE User

This will raise the following exception:

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. |
-------------------------------------

Drop 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.