Dropping user-defined types (UDTs), tables, columns or indexes

Dropping a type

You can delete a type. All tables that use the UDT must first be deleted.

  • graphQL command

  • Result

# drop a UDT
mutation dropType {
  dropType(keyspaceName:"library", typeName:"address_type", ifExists:true)
}
{
  "data": {
    "dropType": true
  }
}

Dropping a table

You can delete a table. All data will be deleted along with the table schema.

  • graphQL command

  • cURL command

  • Result

# drop a table
mutation dropTableBook {
  dropTable(keyspaceName:"library",
    tableName:"article")
}
curl -sL --request POST --url http://$ASTRA_CLUSTER_ID-$ASTRA_REGION.apps.astra.datastax.com/api/graphql-schema \
--header "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
--header 'Content-Type: application/json' \
--data-raw '{"query":"mutation dropTableArticle {\n  dropTable(keyspaceName:\"library\",\n    tableName:\"article\")\n}","variables":{}}'
{
  "data": {
    "dropTable": true
  }
}

IF EXISTS option

You can delete a table after checking that it exists with the ifExists option. All data will be deleted along with the table schema.

  • graphQL command

  • cURL command

  • Result

# drop a table if it exists
mutation dropTableIfExists {
  dropTable(keyspaceName:"library",
    tableName:"magazine",
  ifExists: true)
}
curl -sL --request POST --url http://$ASTRA_CLUSTER_ID-$ASTRA_REGION.apps.astra.datastax.com/api/graphql-schema \
--header "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
--header 'Content-Type: application/json' \
--data-raw '{"query":"mutation dropTableIfExists {\n  dropTable(keyspaceName:\"library\",\n    tableName:\"magazine\",\n  ifExists: true)\n}","variables":{}}'
{
  "data": {
    "dropTable": true
  }
}

Dropping columns from table schema

If you find an attribute is no longer required in a table, you can remove a column. All column data will be deleted along with the column schema.

  • graphQL command

  • cURL command

  • Result

# drop a column format from a table
mutation dropColumnFormat {
    alterTableDrop(
    keyspaceName:"library",
    tableName:"book",
    toDrop:["format"]
  )
}
curl -sL --request POST --url http://$ASTRA_CLUSTER_ID-$ASTRA_REGION.apps.astra.datastax.com/api/graphql-schema \
--header "X-Cassandra-Token: $ASTRA_DB_APPLICATION_TOKEN" \
--header 'Content-Type: application/json' \
--data-raw '{"query":"mutation dropColumnFormat {\n    alterTableDrop(\n    keyspaceName:\"library\",\n    tableName:\"book\",\n    toDrop:[\"format\"]\n  )\n}","variables":{}}'
{
  "data": {
    "alterTableDrop": true
  }
}

Dropping an index from table schema

If you find an index is no longer required on a table column, or you need to change the index, you can remove it. All index data will be deleted along with the index schema.

  • graphQL command

  • cURL command

  • Result

mutation dropIndexBdate {

  reader: dropIndex(
      keyspaceName:"library",
      indexName:"reader_bdate_idx"
  )
}
curl --location --request POST 'https://8319febd-e7cf-4595-81e3-34f45d332d2a-us-east1.apps.astra.datastax.com/api/graphql-schema' \
--header 'X-Cassandra-Token: AstraCS:txZMMdsloiGKPZhosGAnMsHY:0d54c888f49f4c5f3201a057c5e7124c30fa573a687fd16f23cb9c98167c26c8' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"mutation dropIndexBdate {\n\n  reader: dropIndex(\n      keyspaceName:\"library\",\n      indexName:\"reader_bdate_idx\"\n  )\n}","variables":{}}'
{
  "data": {
    "reader": true
  }
}