Update attribute columns of a mapping table

Updated at:

You can execute the ALTER TABLE statement to add or remove an attribute column in an existing mapping table.

Note

For more information, see DDL operations.

Prerequisites

Usage notes

  • Execute a CREATE TABLE statement to create a mapping table for the data table first, and then use an ALTER TABLE statement to update attribute columns.

  • Each ALTER TABLE statement can add or remove only one attribute column. To update multiple attribute columns, execute an ALTER TABLE statement for each column.

  • An ALTER TABLE statement updates only the mapping table schema. It does not update the data storage schema of the Tablestore table.

  • An ALTER TABLE statement cannot add or remove primary key columns from a mapping table.

  • After you execute an ALTER TABLE statement, the SQL engine refreshes the mapping table asynchronously. The refresh can take up to 30 seconds. During the refresh, queries that return all attribute columns may not return the newly added column.

  • To change the definition of an existing attribute column, use DROP COLUMN to remove the column and then use ADD COLUMN to add the column with the new definition.

Parameters

Parameter

Description

query

The SQL statement. Configure this parameter based on the required feature.

Examples

  • Add an attribute column to a mapping table

    The following sample code provides an example on how to add the colvalue column of the BIGINT type to a mapping table named exampletable:

    /// <summary>
    /// Add the colvalue column of the BIGINT type to a mapping table named exampletable. 
    /// </summary>
    /// <param name="otsClient"></param>
    public static void AlterTableAddColumn(OTSClient otsClient)
    {
        SQLQueryRequest sqlQueryRequest = new SQLQueryRequest("alter table exampletable add column colvalue bigint");
        otsClient.SQLQuery(sqlQueryRequest);
    }
  • Remove an attribute column from a mapping table

    The following sample code provides an example on how to remove the colvalue column of the BIGINT type from a mapping table named exampletable:

    /// <summary>
    /// Remove the colvalue column of the BIGINT type from a mapping table named exampletable.  
    /// </summary>
    /// <param name="otsClient"></param>
    public static void AlterTableDropColumn(OTSClient otsClient)
    {
        SQLQueryRequest sqlQueryRequest = new SQLQueryRequest("alter table exampletable drop column colvalue");
        otsClient.SQLQuery(sqlQueryRequest);
    }
Note

When you update attribute columns of a mapping table, you can remove attribute columns that you no longer require and then add attribute columns based on your business requirements.

FAQ

References

  • To accelerate SQL data queries and computing, you can create a secondary index or a search index. For more information, see Index selection policy and Computation pushdown.

  • After you update attribute columns of a mapping table, you can execute the SELECT statement to query and analyze data by using the mapping table. For more information, see Query data.

  • If you want to query the description of a table, you can execute the DESCRIBE statement. For more information, see Query information about tables.

  • If you no longer require a mapping table that is created for a table or a search index, you can execute the DROP MAPPING TABLE statement to delete the mapping table. For more information, see Delete mapping tables.

  • If you want to view the index information about a table, you can execute the SHOW INDEX statement. For more information, see Query index information about tables.

  • If you want to query the names of mapping tables in the current database, you can execute the SHOW TABLES statement. For more information, see List the names of tables.