DROP TYPE
Immediately and irreversibly removes a user-defined type (UDT). This includes the UDT specification in the keyspace and associated metadata.
If the UDT is in use by a table, index, or another type, the command fails in most cases. You must drop the dependent usage before dropping the type.
If you need to retain the data from UDT columns, take action to preserve the data before dropping the UDT column. For example, you could rewrite the data to one or more new columns, or you could export the data with DataStax Bulk Loader (DSBulk) to CSV or JSON format for external storage.
- Frozen columns
-
There is no restriction on dropping UDTs in frozen columns.
UDTs in frozen columns are dropped without blocking the operation.
- Non-frozen columns
-
You must drop the column, and then drop the UDT.
The following error occurs when attempting to drop a UDT that is in use by a column:
InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot drop user type cycling.basic_info as it is still used by table cycling.cyclist_stats"However,
ALTER TABLEcannot be used to drop a non-frozen column with a UDT. The following error occurs:InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot drop non-frozen column basics of user type basic_info"Instead, you must drop the entire table before dropping the UDT. Take any necessary action to preserve your data, unless you no longer need the table.
- Indexed columns
-
You must drop the index, and then drop the UDT.
The following error occurs when attempting to drop a UDT that is used in a column with a secondary index:
InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot drop column races because it has dependent secondary indexes (cyclist_races_races_idx)"
Synopsis
DROP TYPE [ IF EXISTS ] [<keyspace_name>.]<type_name> ;
| Syntax conventions | Description |
|---|---|
UPPERCASE |
Literal keyword. |
Lowercase |
Not literal. |
|
Variable value. Replace with a user-defined value. |
|
Optional.
Square brackets ( |
|
Group.
Parentheses ( |
|
Or.
A vertical bar ( |
|
Repeatable.
An ellipsis ( |
|
Single quotation ( |
|
Map collection.
Braces ( |
|
Set, list, map, or tuple.
Angle brackets ( |
|
End CQL statement.
A semicolon ( |
|
Separate the command line options from the command arguments with two hyphens ( |
|
Search CQL only: Single quotation marks ( |
|
Search CQL only: Identify the entity and literal value to overwrite the XML element in the schema and solrConfig files. |
Parameters
| Parameter | Description | Default |
|---|---|---|
|
Optional. Only drop the type if it exists. If the type does not exist, no error is thrown. |
If omitted, the command fails and throws an error if there is no type with the specified name in the keyspace. |
|
Optional. Name of the keyspace that contains the type to drop. |
If not specified, the current keyspace is used. |
|
Name of the type to drop. |
Examples
-
If needed, prepare to drop the UDT:
-
Drop an index that uses the type:
DROP INDEX IF EXISTS cycling.races_idx; -
Drop a column that uses the type:
ALTER TABLE cycling.cyclist_races DROP races; -
Drop an entire table that uses the type, if the UDT usage prevents dropping the column:
DROP TABLE IF EXISTS cycling.cyclist_races;
-
-
Drop the type:
DROP TYPE IF EXISTS cycling.race;