Open In App

Modifying a user-defined type (UDT)

Last Updated : 19 Dec, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

Pre-requisite – Overview of User Defined Type
In this article, we will discuss how we can change the UDT column and also we can add, Rename the existing column in User Defined Type. So, let’s have a look.

Now, first, we are going to create a UDT table and then we will modify it as per need. So let’s consider Electricity_bill is a table name.

CREATE TYPE Electricity_bill
 (
  Bill_id int,
  Due_date date,
  Submit_date date
 ); 

Now, let’s verify the user-defined type by using the following CQL query given below.

DESCRIBE TYPE Electricity_bill; 

Output:

To add a new column in the user-defined type used the following CQL query.

ALTER TYPE cluster1.Electricity_bill
ADD name text; 

Output:

DESCRIBE TYPE Electricity_bill; 

To rename the existing field ‘RENAME’ keyword can be used. Let’s have a look.

ALTER TYPE cluster1.Electricity_bill
RENAME name TO full_name; 

Now, let’s verify the modifying user-defined type by using the following CQL query given below.

DESCRIBE TYPE Electricity_bill; 

Output:

Restriction: In the case of modifying UDTs, there is a restriction that modifying UDTs in the primary key is not supported and also not supported for the index column and changing column type of UDTs is also not supported.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads