Skip to main content
The DROP TYPE statement drops a specified enumerated data type from the current database.
The DROP TYPE statement performs a schema change. For more information about how online schema changes work in CockroachDB, see Online Schema Changes.

Synopsis

drop_type syntax diagram
To drop a domain data type, use the DROP DOMAIN statement. DROP DOMAIN shares its syntax and behavior with DROP TYPE, as shown in the synopsis. For an example, refer to Drop a domain.

Parameters

Required privileges

The user must be the owner of the type or domain, or the owner of the schema that contains the type or domain.

Details

  • Without CASCADE, you cannot drop a type or domain that is in use by a table.
  • Without CASCADE, you cannot drop a type that a domain data type is based on. Drop the domain first.
  • You can only drop a user-defined type from the database that contains the type.

Examples

Drop a single type

Drop multiple types

Drop a domain

Create a domain data type and a table that uses it:
A domain that is in use by a table cannot be dropped:
Drop the dependent table, then drop the domain:

Drop a type and its dependent objects

The following example uses CASCADE to drop an enumerated type together with a domain that is based on it and a table column that uses the domain. Create an enumerated type, a domain based on the type, and a table that uses the domain:
Without CASCADE, the type cannot be dropped because the domain depends on it:
Drop the type with CASCADE:
The statement drops the status type, the account_status domain, and the status column. The accounts table and its other columns are kept:

Known limitations

  • DROP TYPE ... CASCADE returns an error if a column of the type is part of a table’s primary key, and nothing is dropped. PostgreSQL instead drops the column, which also drops the table’s primary key.

See also