Alter a user-defined type (UDT) (C#)

Adds and renames fields in a user-defined type (UDT).

This command can’t rename the user-defined type itself or drop fields from the user-defined type. Instead, you must drop the user-defined type and then re-create the user-defined type with the desired name and fields.

Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart.

Result

Adds or renames fields in a user-defined type.

Does not return anything.

Parameters

Use the AlterTypeAsync method, which belongs to the Database class. You can also use AlterType, which is the synchronous version of the method.

Method signature
public Task AlterTypeAsync(
  string typeName,
  IAlterTypeOperation operation,
  AlterTypeOptions options = null
);
public Task AlterTypeAsync<T>(
  IAlterTypeOperation operation,
  AlterTypeOptions options = null
) where T : new();
Name Type Summary

typeName

string

The name of the user-defined type to alter.

If you use a custom user-defined type class and do not specify this parameter, the client attempts to extract it from first from the [UserDefinedType("TYPE_NAME")] attribute, then from the name of the class. For more information and examples, see Custom typing for collections.

operation

IAlterTypeOperation

The alter operation to perform.

Can be one of the following:

  • An AlterTypeAddFields object that defines the name and data type of each field to add to the user-defined type. You can use any supported data type, except for maps, lists, sets, or other user-defined types.

  • An AlterTypeRenameFields object that describes the fields to rename.

See the examples for usage.

options

AlterTypeOptions

Optional. General API options for this operation, including the timeout. For more information and examples, see Customize API interaction.

Examples

The following examples demonstrate how to alter a user-defined type.

Rename fields

using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Tables;

namespace Examples;

public class Program
{
  static async Task Main()
  {
    // Get an existing table
    var client = new DataAPIClient();
    var database = client.GetDatabase(
      "API_ENDPOINT",
      "APPLICATION_TOKEN"
    );

    // Rename fields in a user-defined type
    await database.AlterTypeAsync(
      "member",
      new AlterTypeRenameFields(
        new() { ["name"] = "first_name", ["is_active"] = "is_member" }
      )
    );
  }
}

Add fields

using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Tables;
using DataStax.AstraDB.DataApi.Utils;

namespace Examples;

public class Program
{
  static async Task Main()
  {
    // Get an existing table
    var client = new DataAPIClient();
    var database = client.GetDatabase(
      "API_ENDPOINT",
      "APPLICATION_TOKEN"
    );

    // Add fields to a user-defined type
    await database.AlterTypeAsync(
      "member",
      new AlterTypeAddFields(
        new()
        {
          ["email"] = DataAPIType.Text(),
          ["credits"] = DataAPIType.Int(),
        }
      )
    );
  }
}

Rename and add fields

You cannot use the client to rename and add fields in the same call. Make separate calls, or use HTTP directly.

Client reference

For more information, see the client reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use Manage Privacy Choices

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: Contact IBM