DROP TABLE
Description
Deletes a table.
Precautions
- DROP TABLE forcibly deletes a specified table. After a table is deleted, the indexes that depend on the table will be deleted. Deleting a partitioned table also deletes all partitions in the table.
- The owner of a table, the owner of the schema of the table, users granted with the DROP permission on the table, or users granted with the DROP ANY TABLE permission can delete the specified table. When separation of duties is disabled, the system administrator has the permission to delete the specified table by default.
Syntax
DROP [TEMPOARARY] TABLE [ IF EXISTS ]
{ [schema.]table_name } [, ...] [ CASCADE | RESTRICT ] [ PURGE ];
Parameters
- IF EXISTS
Reports a notice instead of an error if the specified table does not exist.
- schema
Schema name.
- table_name
Table name.
- CASCADE | RESTRICT
- CASCADE: allows cascade deletion of the objects (such as views) that depend on the table.
- RESTRICT (default): refuses to delete the table if any objects depend on it.
This attribute is supported only as syntax but does not take effect when the version compatibility control parameter m_format_dev_version of an M-compatible database is set to 's1' or later.
- PURGE
Specifies that even if the recycle bin function is enabled, the table is physically dropped instead of being moved to the recycle bin.
Examples
-- Create the test table. m_db=# CREATE TABLE test(c1 int, c2 int); -- Drop the test table. m_db=# DROP TABLE IF EXISTS test; -- Failed to delete the table when there are views dependent on the table. m_db=# create schema s1; m_db=# create table s1.t1(a int); m_db=# create view s1.v1 as select * from s1.t1; m_db=# create view s1.v2 as select * from s1.v1; m_db=# drop table s1.t1; ERROR: cannot drop table s1.t1 because other objects depend on it DETAIL: view s1.v1 depends on table s1.t1 view s1.v2 depends on view s1.v1 HINT: Please drop the dependent first. m_db=# drop table s1.t1 cascade; ERROR: cannot drop table s1.t1 because other objects depend on it DETAIL: view s1.v1 depends on table s1.t1 view s1.v2 depends on view s1.v1 HINT: Please drop the dependent first.
Helpful Links
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot