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.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com