Query information about a table

Updated at:

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

A Tablestore client is initialized. For more information, see Initialize a Tablestore client.

Usage notes

The SQL query feature is supported by Tablestore SDK for .NET V5.0.0 and later. When you use the SQL query feature, make sure that a supported version of Tablestore SDK for .NET is installed.

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));
    }
}