Delete a secondary index

Updated at:

Use Tablestore SDK for Go to delete a global or local secondary index without affecting the data table or its data.

Prerequisites

Precautions

A deleted secondary index cannot be recovered. To use the index again, create a new secondary index.

Parameters

Parameter

Description

MainTableName

The name of the data table.

IndexName

The name of the index table.

Example

This example deletes a secondary index from a data table.

func DeleteIndex(client *tablestore.TableStoreClient, tableName string, indexName string) {
    deleteIndex := &tablestore.DeleteIndexRequest{
        MainTableName: tableName,
        IndexName:     indexName,
    }
    resp, err := client.DeleteIndex(deleteIndex)
    if err != nil {
        fmt.Println("Failed to delete the secondary index: ", err)
    } else {
        fmt.Println("Successfully deleted the secondary index: ", resp)
    }
}