You can execute the ALTER TABLE statement to add or remove an attribute column in an existing mapping table.
For more information, see DDL operations.
Prerequisites
-
An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.
-
A mapping table is created. For more information, see Create mapping tables.
Usage notes
-
Execute a
CREATE TABLEstatement to create a mapping table for the data table first, and then use anALTER TABLEstatement to update attribute columns. -
Each
ALTER TABLEstatement can add or remove only one attribute column. To update multiple attribute columns, execute anALTER TABLEstatement for each column. -
An
ALTER TABLEstatement updates only the mapping table schema. It does not update the data storage schema of the Tablestore table. -
An
ALTER TABLEstatement cannot add or remove primary key columns from a mapping table. -
After you execute an
ALTER TABLEstatement, 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 COLUMNto remove the column and then useADD COLUMNto 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); }
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
SELECTstatement 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
DESCRIBEstatement. 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 TABLEstatement 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 INDEXstatement. 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 TABLESstatement. For more information, see List the names of tables.