User-defined type
A user-defined type facilitates handling multiple fields of related information in a table. Applications that required multiple tables can be simplified to use fewer tables by using a user-defined type to represent the related fields of information instead of storing the information in a separate table. The address type example demonstrates how to use a user-defined type.
You can create, alter, and drop a user-defined type using these commands:
The cqlsh utility includes these commands for describing a user-defined type or listing all user-defined types:
Accessing a UDT in a keyspace
When you create a user-defined type, by default, the current keyspace is its scope. Use dot notation , for example, KEYSPACE_NAME
.UDT_NAME
, to create a UDT in a specific keyspace.
You can use UDTs only in CREATE TABLE
or ALTER TABLE
statements within the same keyspace where the UDT is defined. However, you can use UDTs in SELECT
, INSERT
, UPDATE
statements with dot notation in any keyspace.