You can execute the show tables statement to query the names of tables in the current instance.
For more information about the SHOW TABLES statement, see List mapping table names.
Prerequisites
- An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.
- A mapping table is created. For more information, see Create a mapping table.
Usage notes
Tablestore SDK for .NET V5.0.0 or later supports the SQL query feature. To use the SQL query feature, make sure that Tablestore SDK for .NET V5.0.0 or later is used. 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. |
Example
The following sample code provides an example on how to execute the SHOW TABLES statement to list the names of mapping tables.
/// <summary>
/// Query the names of tables in an instance.
/// </summary>
/// <param name="otsClient"></param>
public static void ShowTable(OTSClient otsClient)
{
SQLQueryRequest sqlQuery = new SQLQueryRequest("show tables");
SQLQueryResponse sqlQueryResponse = otsClient.SQLQuery(sqlQuery);
SQLTableMeta sqlTableMeta = sqlQueryResponse.GetSQLResultSet().GetSQLTableMeta();
Console.WriteLine(JsonConvert.SerializeObject(sqlTableMeta.GetSchema()));
ISQLResultSet resultSet = sqlQueryResponse.GetSQLResultSet();
while (resultSet.HasNext())
{
ISQLRow row = resultSet.Next();
Console.WriteLine(JsonConvert.SerializeObject(row.GetString(0)));
}
List<string> tables = SQLUtils.ParseShowTablesResponse(sqlQueryResponse);
foreach (string table in tables)
{
Console.WriteLine("Table: {0}", table);
}
}References
After you query the names of the mapping tables, perform operations based on your business requirements.
To use a mapping table to query data that meets specific conditions, execute the
SELECTstatement. For more information, see Query data.To query details of a mapping table such as field names and field types, execute the
DESCRIBEstatement. For more information, see Query information about a table.To update the attribute column of a mapping table after an attribute column of the data table is changed, execute the
ALTER TABLEstatement. For more information, see Update attribute columns of mapping tables.To delete a mapping table, execute the
DROP MAPPING TABLEstatement. For more information, see Delete a mapping table.