Data table operations
Create, select, view, update, and drop data tables with the Tablestore command line interface (CLI).
Prerequisites
A Tablestore CLI installation with configured access credentials. For more information, see Tablestore CLI.
A Tablestore instance. For more information, see Instance operations.
Create a table
To create a data table, specify primary key columns and optionally configure data TTL and version limits. Alternatively, create a table from a JSON configuration file.
create -t tableName --pk '[{"c":"col1","t":"string"},{"c":"col2","t":"integer"}]' [--ttl seconds] [--version max]
|
Parameter |
Required |
Description |
|
|
Yes |
The name of the data table. |
|
|
Yes |
The primary key column definitions in JSON array format. Each element contains the following fields:
Note
Attribute columns do not need to be defined when creating a data table. Each row in Tablestore can have different attribute columns. Attribute column names are specified when you write data. A data table supports up to 4 primary key columns. The first primary key column is the partition key by default. Primary key configurations cannot be modified after the table is created. |
|
|
No |
The table type. Default value: |
|
|
No |
The data time-to-live (TTL), in seconds. Default value: |
|
|
No |
The maximum number of versions. Default value: Important
Tablestore does not enforce a hard limit on the maximum number of versions. However, for optimal performance and usability, keep this value at 500 or less. |
|
|
No |
The reserved read or write throughput, in capacity units (CUs). Default value: Note
|
|
|
No |
|
|
|
No |
Predefined columns in JSON array format. Required for secondary indexes. Each element contains the following fields:
Note
A data table supports up to 32 predefined columns by default. |
|
|
No |
Specifies whether to enable Stream. Default value: |
|
|
No |
The expiration period of Stream data, in hours. Default value: |
|
|
No |
The path to a JSON configuration file for creating the table. |
Create a basic data table:
create -t mytable --pk '[{"c":"uid","t":"string"},{"c":"pid","t":"integer"}]'
Create a data table with an auto-increment column and TTL:
create -t mytable --pk '[{"c":"uid","t":"string"},{"c":"pid","t":"integer","opt":"auto"}]' --ttl 864000 --version 1
Create a data table with predefined columns for secondary indexes:
create -t mytable --pk '[{"c":"uid","t":"string"},{"c":"pid","t":"integer"}]' --defined '[{"c":"name","t":"string"},{"c":"age","t":"integer"}]'
Create a data table from a configuration file:
Windows
create -i D:\\localpath\\filename.json
Linux and macOS
create -i /localpath/filename.json
Configuration file example:
{
"Name": "mytable",
"Meta": {
"Pk": [
{"C": "uid", "T": "string", "Opt": "none"},
{"C": "pid", "T": "integer", "Opt": "none"}
]
},
"Option": {
"TTL": 864000,
"Version": 3
},
"CU": {
"Read": 0,
"Write": 0
}
}
Select a table
Select a data table for subsequent data operations.
use --wc -t tableName
|
Parameter |
Required |
Description |
|
|
No |
Selects a wide column data table. |
|
|
Yes |
The name of the table. |
Example:
use --wc -t mytable
List table names
List the names of tables in the current instance. Filter results by table type as needed.
list [--wc | --all] [--detail]
|
Parameter |
Required |
Description |
|
|
No |
Lists only data tables. |
|
|
No |
Lists all table types. |
|
|
No |
Displays detailed table information. |
Example:
list --wc
View table details
View the configuration details of a data table or index table.
desc [-t tableName] [-f json|table] [-o outputFile]
|
Parameter |
Required |
Description |
|
|
No |
The name of the data table or index table. If omitted, defaults to the table selected by |
|
|
No |
The output format. Valid values: |
|
|
No |
Saves the output to a local file. |
Example:
desc -t mytable
Update a table
Update the configuration of a data table, such as data TTL, maximum number of versions, and reserved throughput.
alter -t tableName [--ttl seconds] [--version max] [--read_cu n] [--write_cu n]
|
Parameter |
Required |
Description |
|
|
Yes |
The name of the table. If a table is selected with |
|
|
No |
The data time-to-live (TTL), in seconds. The value must be greater than or equal to 86400 (one day) or equal to -1 (data never expires). |
|
|
No |
The maximum number of versions. The value must be a non-zero integer. |
|
|
No |
The reserved read or write throughput, in capacity units (CUs). This configuration is supported only for high-performance instances in CU mode. |
|
|
No |
|
|
|
No |
Specifies whether to enable Stream. |
|
|
No |
The expiration period of Stream data, in hours. |
|
|
No |
Specifies whether to disable update operations. |
Set the TTL to one day and the maximum number of versions to 1:
alter -t mytable --ttl 86400 --version 1
Drop a table
Drop a specified data table.
drop -t tableName [-y]
|
Parameter |
Required |
Description |
|
|
Yes |
The name of the table. |
|
|
No |
Skips the confirmation prompt and drops the table directly. |
Example:
drop -t mytable -y