All Products
Search
Document Center

Tablestore:Create a mapping table

Last Updated:Aug 29, 2024

You can execute the CREATE TABLE statement to create a mapping table for an existing table or search index.

Note

For more information about the CREATE TABLE statement, see Create a mapping table for a table and Create mapping tables for search indexes.

Prerequisites

  • An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.

  • A data table is created. For more information, see Create a data table.

    If you want to use a mapping table that is created for a search index to query data, the search index is created.

Usage notes

Tablestore SDK for .NET V5.0.0 or later supports SQL queries. To perform SQL queries by using Tablestore SDK for .NET, make sure that your SDK version is 5.0.0 or later. We recommend that you use the latest SDK. For more information, see Version history of Tablestore SDK for .NET.

Parameters

Parameter

Description

query

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

Examples

Note

This topic describes how to create a mapping table for a table. If you want to create a mapping table for a search index, replace the SQL statement in the sample code with the SQL statement that is used to create a mapping table for a search index.

The following sample code provides an example on how to execute the CREATE TABLE `test_table` (`pk0` VARCHAR(1024), `pk1` BIGINT(20), `col0` MEDIUMTEXT, `col1` BIGINT(20), `col2` DOUBLE, `col3` BOOL, `col4` MEDIUMBLOB, `date_col` MEDIUMTEXT, `geo_col` MEDIUMTEXT, `col0_v1` MEDIUMTEXT, `col0_v2` MEDIUMTEXT, PRIMARY KEY(`pk0`,`pk1`)); statement to create a mapping table for the test_table table:

/// <summary>
/// Create a mapping table for a data table. 
/// </summary>
/// <param name="otsClient"></param>
public static void CreateMappingTable(OTSClient otsClient)
{
    string sqlCommand = @"CREATE TABLE `test_table` (
        `pk0` VARCHAR(1024),
        `pk1` BIGINT(20),
        `col0` MEDIUMTEXT,
        `col1` BIGINT(20),
        `col2` DOUBLE,
        `col3` BOOL,
        `col4` MEDIUMBLOB,
        `date_col` MEDIUMTEXT,
        `geo_col` MEDIUMTEXT,
        `col0_v1` MEDIUMTEXT,
        `col0_v2` MEDIUMTEXT,
        PRIMARY KEY(`pk0`,`pk1`)
    );";

    SQLQueryRequest sqlQueryRequest = new SQLQueryRequest(sqlCommand);

    SQLQueryResponse sqlQueryResponse = otsClient.SQLQuery(sqlQueryRequest);
}

FAQ

How do I troubleshoot common errors of SQL queries?

References

  • If you want to accelerate data queries and computing by executing SQL statements, you can create a secondary index or a search index. For more information, see Index selection policy and Computing pushdown.

  • You can execute the SELECT statement to query and analyze data in the table for which you created a mapping table. For more information, see Query data.

  • If an attribute column is added to or removed from a data table, you can execute the ALTER TABLE statement to modify the mapping table that is created for the data table. For more information, see Update attribute columns of mapping tables.

  • 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 a table.

  • If you want to list 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.