Modifying a user-defined type (UDT)

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.

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.