All Products
Search
Document Center

Tablestore:Query information about a table

Last Updated:Aug 29, 2024

You can execute the DESCRIBE statement to query the information about tables, such as the field names and field types.

Note

For more information about the DESCRIBE statement, see Query information about tables.

Prerequisites

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 the parameter based on the required feature.

Examples

The following sample code provides an example on how to execute the describe test_table statement to query the information about test_table:

/// <summary>
/// Query information about a table. 
/// </summary>
/// <param name="otsClient"></param>
public static void DescribeTable(OTSClient otsClient)
{
    SQLQueryRequest sqlQueryRequest = new SQLQueryRequest("describe test_table");

    SQLQueryResponse sqlQueryResponse = otsClient.SQLQuery(sqlQueryRequest);

    SQLTableMeta sqlTableMeta = sqlQueryResponse.GetSQLResultSet().GetSQLTableMeta();
    Console.WriteLine(JsonConvert.SerializeObject(sqlTableMeta.GetSchema()));

    ISQLResultSet resultSet = sqlQueryResponse.GetSQLResultSet();
    while (resultSet.HasNext())
    {
        ISQLRow row = resultSet.Next();
        Console.WriteLine(row.GetString(0) + " " + row.GetString(1) + " " + row.GetString(2) + " " +
                          row.GetString(3) + " " + row.GetString(4) + " " + row.GetString(5));
    }
}