DROP TABLE
To delete a table definition, use the DROP TABLE
statement:
DROP TABLE [IF EXISTS] table-name
where:
-
IF EXISTS
is optional. If you use this option and the specified table does not exist, the system returns a message:
If you do not specifysql-> drop table if exists foo; Statement did not require execution
IF EXISTS
, and the table does not currently exist, the DROP statement returns as follows:
If you specifysql-> drop table foo; Error handling command drop table foo: Error: User error in query: DROP TABLE failed for table foo: Table does not exist: foo
IF EXISTS
, and the table exists, the DROP statement executes successfully:sql-> create table foo (first string, second integer, primary key (second)); Statement completed successfully sql-> drop table if exists foo; Statement completed successfully
-
table-name is the name of the table you want to drop.
As soon as you execute the DROP TABLE statement, users can no longer access the deleted table or its data. Deleting all of the table data occurs asynchronously in the background after you execute the DROP TABLE statement.
DROP TABLE
statement in each region separately.
Note:
In a case where an MR Table is dropped in all remote regions but still exists in local region, it still continues to be an MR Table linked with a single region. Such an MR Table with a single region can be expanded to more regions in future. That is, you can add new regions to this table in future, as needed.If the table to drop has child tables, you must drop those first. For example, if you have these tables:
-
myTable
-
myTable.childTable1
-
myTable.childTable2
You must first drop myTable.childTable1
and myTable.childTable2
before you can drop the parent myTable
. If you try to drop the parent, the statement returns an error.