Data table operations

更新时间: 2026-06-08 15:26:19

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

-t, --table

Yes

The name of the data table.

-k, --pk

Yes

The primary key column definitions in JSON array format. Each element contains the following fields:

  • c (required): The name of the primary key column.

  • t (required): The type of the primary key column. Valid values: string, integer, binary.

  • opt (optional): Default value: none. Set to auto to use the column as an auto-increment primary key column. For more information about auto-increment primary key columns, see Auto-increment primary key column.

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.

-m, --model

No

The table type. Default value: widecolumn (data table). To create a time series table, see TimeSeries model.

--ttl

No

The data time-to-live (TTL), in seconds. Default value: -1 (data never expires). The value must be greater than or equal to 86400 (one day) or equal to -1.

--version

No

The maximum number of versions. Default value: 1. The value must be a non-zero integer.

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.

--read_cu

No

The reserved read or write throughput, in capacity units (CUs). Default value: 0 (pay-as-you-go).

Note
  • This configuration is supported only for data tables in high-performance instances in CU mode.

  • If the reserved read or write throughput is set to a non-zero value, you are charged regardless of whether read or write requests are sent.

--write_cu

No

-d, --defined

No

Predefined columns in JSON array format. Required for secondary indexes. Each element contains the following fields:

  • c (required): The name of the predefined column.

  • t (required): The type of the predefined column. Valid values: string, integer, binary, double, bool.

Note

A data table supports up to 32 predefined columns by default.

--stream_enable

No

Specifies whether to enable Stream. Default value: false.

--stream_expire

No

The expiration period of Stream data, in hours. Default value: 24.

-i, --input

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

--wc

No

Selects a wide column data table.

-t, --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

-w, --wc

No

Lists only data tables.

-a, --all

No

Lists all table types.

-d, --detail

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

-t, --table

No

The name of the data table or index table. If omitted, defaults to the table selected by use.

-f, --print_format

No

The output format. Valid values: json (default) and table.

-o, --output

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

-t, --table

Yes

The name of the table. If a table is selected with use, this parameter is optional.

--ttl

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).

--version

No

The maximum number of versions. The value must be a non-zero integer.

--read_cu

No

The reserved read or write throughput, in capacity units (CUs). This configuration is supported only for high-performance instances in CU mode.

--write_cu

No

--stream_enable

No

Specifies whether to enable Stream.

--stream_expire

No

The expiration period of Stream data, in hours.

--disallow_update

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

-t, --table

Yes

The name of the table.

-y, --yes

No

Skips the confirmation prompt and drops the table directly.

Example:

drop -t mytable -y
上一篇: Wide Column model 下一篇: Data operations
阿里云首页 表格存储 相关技术圈