title: "DROP TABLE"
description: "DROP TABLE
removes a table from Materialize."
menu:
main:
parent: commands
DROP TABLE
removes a table from Materialize.
Tables store non-streaming data that is inserted via INSERT
statements. DROP TABLE
removes a table from Materialize.
{{< diagram "drop-table.svg" >}}
Field | Use |
---|---|
IF EXISTS | Do not return an error if the named table doesn't exist. |
_tablename | The name of the table to remove. |
CASCADE | Remove the table and its dependent objects. |
RESTRICT | Don't remove the table if any non-index objects depend on it. (Default.) |
Create a table t and verify that it was created:
CREATE TABLE t (a int, b text NOT NULL);
SHOW TABLES;
TABLES
------
t
Remove the table:
DROP TABLE t;
Create a table t:
CREATE TABLE t (a int, b text NOT NULL);
INSERT INTO t VALUES (1, 'yes'), (2, 'no'), (3, 'maybe');
SELECT * FROM t;
a | b
---+-------
2 | no
1 | yes
3 | maybe
(3 rows)
Create a materialized view from t:
CREATE MATERIALIZED VIEW t_view AS SELECT sum(a) AS sum FROM t;
SHOW MATERIALIZED VIEWS;
name | cluster
--------+---------
t_view | default
(1 row)
Remove table t:
DROP TABLE t CASCADE;
You can use either of the following commands:
DROP TABLE t;
DROP TABLE t RESTRICT;
DROP TABLE IF EXISTS t;
The privileges required to execute this statement are:
{{< include-md file="shared-content/sql-command-privileges/drop-table.md" >}}