This topic describes how to create a mapping table for a data table, query all mapping tables of a data table in an instance, query information about a mapping table, and query data in a table in the SQL mode.
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.
The following sample code shows how 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 of a data table in an instance.
Run the SHOW TABLES;
command to query the mapping tables of a data table in an instance.
+----------------------+
| Tables_in_myinstance |
+----------------------+
| mytable |
+----------------------+
| mytstable |
+----------------------+
| mytstable::meta |
+----------------------+
In the preceding command output, mytable is the data table for which mapping tables are created, mytstable is a time series data table, and mytstable::meta is 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;
The following result is returned:+-------+---------------+------+-----+-------+ | 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 | | | +-------+---------------+------+-----+-------+
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;
- Example
The following sample code shows how to delete the mapping table named mytable:
DROP MAPPING TABLE mytable;
Query data in a table
Query data in a table by executing the SELECT statement.
SELECT * FROM mytable;
Exit the SQL mode
Run the exit;
command to exit the SQL mode.