All Products
Search
Document Center

Tablestore:Query data by executing SQL statements

Last Updated:Oct 08, 2026

This topic describes how to use Tablestore SDK for .NET to query data by executing SQL statements.

Usage notes

SQL query is supported in Tablestore SDK for .NET V5.0.0 and later. Make sure that a supported SDK version is installed.

For more information, see Version history of Tablestore SDK for .NET.

Prerequisites

Example

The following example shows how to use the select pk0,pk1,col0,col1,date_col,geo_col from test_table limit 20 statement to query data in the test_table table and return a maximum of 20 rows of data. The system returns the request type of the query statement, the schema of the return value, and the returned results.

/// <summary>
/// Query data.
/// </summary>
/// <param name="otsClient"></param>
public static void QueryData(OTSClient otsClient)
{
    SQLQueryRequest sqlQueryRequest = new SQLQueryRequest("select pk0,pk1,col0,col1,date_col,geo_col from test_table limit 20");

    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("pk0") + " , " + row.GetLong("pk1") + " , " + row.GetString("col0") + " , " +
                          row.GetLong("col1") + " , " + row.GetString("date_col") + " , " + row.GetString("geo_col"));
    }
}

FAQ