After you enter the SQL mode, you can execute SQL statements to create a mapping table for a table, query mapping tables that are created for tables in an instance, query information about a mapping table, query data in a table, and delete a mapping table.
For more information, see Overview.
Enter the SQL mode
Run the sql command to enter the SQL mode.
Create a mapping table
To query data in a data table, you must create a mapping table for the data table.
Run the following command to create a mapping table for the data table named mytable:
CREATE TABLE mytable(
`uid` VARCHAR(1024),
`pid` BIGINT(20),
`b` DOUBLE,
`c` BOOL,
`d` MEDIUMTEXT,
PRIMARY KEY(`uid`,`pid`)
);
Query mapping tables
Query the mapping tables that are created for data tables in an instance.
Run the SHOW TABLES;
command to query the mapping tables that are created for data tables in an instance.
Sample output:
+----------------------+
| Tables_in_myinstance |
+----------------------+
| mytable |
+----------------------+
| mytstable |
+----------------------+
| mytstable::meta |
+----------------------+
In the preceding command output, mytable is a mapping table that is created for a data table, mytstable is a mapping table that is created for a time series data table, and mytstable::meta is a mapping table that is created for a time series metadata table.
Query information about a mapping table
Query information about a mapping table.
Command syntax
DESCRIBE table_name;
Examples
The following sample code shows how to query the information about the mapping table named mytable:
DESCRIBE mytable;
Sample output:
+-------+---------------+------+-----+-------+
| Field | Type | Null | Key | Extra |
+-------+---------------+------+-----+-------+
| uid | varchar(1024) | NO | PRI | |
+-------+---------------+------+-----+-------+
| pid | bigint(20) | NO | PRI | |
+-------+---------------+------+-----+-------+
| b | double | YES | | |
+-------+---------------+------+-----+-------+
| c | tinyint(1) | YES | | |
+-------+---------------+------+-----+-------+
| d | mediumtext | YES | | |
+-------+---------------+------+-----+-------+
Query the data in a table
Query the data in a table by executing the SELECT statement.
The following sample code shows how to query all data in the table named mytable:
SELECT * FROM mytable;
Delete a mapping table
If changes are made to the attribute columns of a data table, you can delete the mapping table of the data table and create a new mapping table.
Command syntax
DROP MAPPING TABLE table_name;
Examples
The following sample code shows how to delete the mapping table named mytable:
DROP MAPPING TABLE mytable;
Exit the SQL mode
Run the exit; command to exit the SQL mode.
FAQ
References
You can use the SQL query feature by using the Tablestore console, Tablestore SDKs, JDBC, and JDBC driver for Go.
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 also use computing engines, such as MaxCompute, Spark, Hive, HadoopMR, Function Compute, Flink, and PrestoDB, to compute and analyze data in tables. For more information, see Overview.