You can access Tablestore in the Tablestore console, in the Tablestore CLI, and by using Tablestore SDKs. You can get started with Tablestore in the Tablestore console. This topic describes how to manage the Wide Column model in the Tablestore console.

Prerequisites

Before you use Tablestore, make sure that you have an Alibaba Cloud account and you have completed the real-name verification. If you do not have an Alibaba Cloud account, the system prompts you to create an Alibaba Cloud account when you activate Tablestore.

Step 1: Activate Tablestore

If Tablestore is activated, skip this operation. You must activate Tablestore only once. You are not charged when you activate Tablestore.

  1. Log on to the Tablestore product page.
  2. Click Get it Free.
  3. On the Tablestore (Pay-as-you-go) page, click Buy Now.
  4. On the Confirm Order page, select I have read and agree to Tablestore (Pay-as-you-go) Agreement of Service and click Activate Now.
    After you activate Tablestore, click Management Console to access the Tablestore console.

    You can also click Console in the upper-right corner of the homepage. Click the fig_tablestore_control_001 icon. In the left-side navigation pane, choose Products and Services > Table Store to go to the Tablestore console.

Step 2: Create an instance

Instances are the basic unit of resource management in Tablestore. Tablestore controls whether applications can access a Tablestore instance and collects statistics about the resources that are used by applications at the instance level. After an instance is created, you can create and manage tables in the instance.

  1. Log on to the Tablestore console.
  2. In the top navigation bar, select a region, for example, China (Hangzhou) or China (Shenzhen).
    The instance types that are available in the region are displayed in the console.
  3. Click Create Instance.
  4. On the On-demand tab in the Billing Method dialog box, specify Instance Name, select an instance type from the Instance Type drop-down list, and specify Instance Description.
    For more information about the naming conventions for instances and how to select an instance type, see Instance.
    Notice
    • You cannot change the instance type after the instance is created.
    • Each Alibaba Cloud account can create up to 10 instances. The name of an instance must be unique within the region where the instance resides.
  5. Click OK.

Step 3: Create a data table

You can read and write data in a data table. When you create a data table, you can create a global secondary index to read data.

  1. On the Overview page, click the name of the instance that you want to manage or click Manage Instance in the Actions column of the instance that you want to manage.
  2. On the Instance Details tab, click Create Table.
    Note You can create up to 64 data tables in an instance.
  3. In the Create Table dialog box, specify Table Name and Primary Key.
    Parameter Description
    Table Name The name of the data table, which is used to identify a data table in an instance.

    The name must be 1 to 255 bytes in length and can contain letters, digits, and underscores (_). The name must start with a letter or an underscore (_).

    Primary Key The primary key column that is used to identify a record in a table.

    Enter a name for the primary key column and select a data type. Click Add Primary Key Column to add a primary key column.

    You can add one to four primary key columns. The first primary key column is the partition key. After you create a data table, you cannot modify the configurations and the order of primary key columns.

    Note
    • In Tablestore, only one primary key column can be used as an auto-increment primary key column for each data table. You cannot use partition keys as auto-increment primary key columns.
    • After you specify a primary key column as an auto-increment primary key column, Tablestore automatically generates a value for the auto-increment primary key column when you write a row of data. The values of auto-increment primary key columns are incremental and unique within the rows that share the same partition key.
    • Naming conventions for primary key columns: The name must be 1 to 255 bytes in length and can contain letters, digits, and underscores (_). The name must start with a letter or an underscore (_).
    • The STRING, INTEGER, and BINARY data types are supported by primary key columns.
  4. (Optional) In the Create Table dialog box, turn on Advanced Settings or Global Secondary Index.
    To configure advanced settings such as time to live (TTL), turn on Advanced Settings. To create a global secondary index, turn on Global Secondary Index.
    • Turn on Advanced Settings and then configure the advanced parameters. The following table describes the parameters.
      Parameter Description
      Time to Live The duration during which the data in the data table can be retained. If the retention period exceeds the TTL value, Tablestore automatically deletes expired data. Unit: seconds.

      Minimum value: 86400 seconds (one day). A value of -1 specifies that the data never expires.

      Max Versions The maximum number of versions that can be retained for data in attribute columns of the data table. If the number of versions of data in attribute columns exceeds the value of this parameter, the system deletes data of earlier versions.

      The value of this parameter for an attribute column is a positive integer.

      Max Version Offset The maximum difference between the current system time and the specified data version. Unit: seconds. The value of the Max Version Offset parameter is a positive integer that can be greater than the number of seconds that have elapsed since 00:00:00 on January 1, 1970 (UTC).

      The difference between the version number and the time at which the data is written must be less than or equal to the value of Max Version Offset. Otherwise, an error occurs when the data is written.

      The valid version range of data in an attribute column is calculated by using the following formula: Valid version range = [Data written time - Max version offset, Data written time + Max version offset).

      Reserved Read Throughput The reserved read or write throughput for the data table.

      This parameter is unavailable for capacity instances. Data type: INTEGER. Valid values: 0 to 100000. Unit: capacity unit (CU).

      • If you set Reserved Read Throughput or Reserved Write Throughput to a value greater than 0, Tablestore allocates and reserves related resources for the data table. After you create the data table, Tablestore charges you for the reserved throughput resources.
      • If you set Reserved Read Throughput or Reserved Write Throughput to 0, Tablestore does not allocate or reserve related resources for the data table.
      Reserved Write Throughput
    • Turn on Global Secondary Index and create a global secondary index.
      • Click + Add next to Pre-defined Column. Specify a name for the predefined column and select a data type from the drop-down list.

        Naming conventions for predefined columns: The name must be 1 to 255 bytes in length and can contain letters, digits, and underscores (_). The name must start with a letter or an underscore (_).

        Predefined columns support the STRING, INTEGER, BINARY, FLOAT, and BOOLEAN data types.

      • Click Add Global Secondary Index. You must configure the Index Name and Primary Key parameters. You can configure the Pre-defined Column parameter based on your requirements.
  5. Click OK.
    After a data table is created, you can view the data table in the Tables section. If the data table that you created is not displayed in the list of data tables, click the fig_tablestore_002 icon to refresh the list of data tables.

Step 4: Read and write data

You can write, update, delete, and read data in a data table.

  1. In the Tables section of the Instance Details tab, click the name of the required data table, and click the Query Data tab. You can also click Query in the Actions column of the data table.
  2. Insert a row of data.
    1. On the Query Data tab, click Insert.
    2. In the Insert dialog box, configure the Primary Key Value parameter. Click Add Column and configure the Name, Type, Value, and Version parameters.
      By default, System Time is selected. This value specifies that the current system time is used as the version number of the data. You can clear System Time and enter the version number of the data.
    3. Click OK.
  3. Update a row of data.
    1. On the Query Data tab, select the row of data that you want to update. Click Update.
    2. In the Update dialog box, modify the types and values of primary key columns, add or remove attribute columns, or update data in or delete data from attribute columns.
      • You can click Add Column to add an attribute column. You can also click the fig_tablestore_005 icon to delete an attribute column.
      • In the first Actions column, if you select Update, you can modify the data in attribute columns. If you select Delete, you can delete the data of the selected version. If you select Delete All, you can delete all versions of the data.
    3. Click OK.
  4. Read data.
    To query data in a single row, perform the following steps:
    1. On the Query Data tab, click Search.
    2. Specify query conditions.
      1. Set Modes to GetRow and select a table or secondary index that you want to query from the Table/Secondary Index drop-down list.
      2. By default, the system returns all columns. To return specified attribute columns, turn off All Columns and enter the attribute columns that you want to return. Separate multiple attribute columns with commas (,).
      3. Configure the Primary Key Value parameter of the row that you want to query.

        The integrity and accuracy of the primary key values affect the query results.

      4. Configure the Max Versions parameter to specify the maximum number of versions to return.
    3. Click OK.
    To query data within a specified range, perform the following steps:
    1. Specify query conditions.
      1. Set Modes to Range Search and select a table or secondary index that you want to query from the Table/Secondary Index drop-down list.
      2. By default, the system returns all columns. To return specified attribute columns, turn off All Columns and enter the attribute columns that you want to return. Separate multiple attribute columns with commas (,).
      3. By default, the system returns all columns. To return specified attribute columns, turn off All Columns and enter the attribute columns that you want to return. Separate multiple attribute columns with commas (,).
      4. Specify Start Primary Key Column and End Primary Key Column.
        Note
        • If you use the range query mode, the values in the first primary key column take priority. If the values of the start primary key column and the end primary key column are the same in the first primary key column, the system uses the values in the second primary key column to perform queries. The query rules for subsequent primary key columns are the same as the query rules for the first two primary key columns.
        • The Custom range is a left-open and right-closed interval.
      5. Configure the Max Versions parameter to specify the maximum number of versions to return.
      6. Set Sequence to Forward Search or Backward Search.
    2. Click OK.
  5. Delete data.
    1. On the Query Data tab, select the row of data that you want to delete. Click Delete.
    2. In the Delete message, click OK.

Step 5: Use SQL to query data

The SQL query feature is compatible with MySQL query syntax and supports table creation by using Data Definition Language (DDL) statements. For existing data tables, you can execute the CREATE TABLE statement to create mapping tables for the existing data tables. Then, you can use SQL statements to access the data in the existing data tables.

  1. On the Overview page, click the name of the instance that you want to manage or click Manage Instance in the Actions column of the instance that you want to manage.
  2. On the Query by Executing SQL Statement tab, create a mapping table.
    1. Click the fig_createtablevitural icon. fig_createtablemapping
    2. In the Create Mapping Table dialog box, select a table, and click Generate SQL Statement.
      The system automatically generates the data structures of the mapping table.
      Notice Make sure that the field data types in the mapping table match the field data types in the data table. For more information about data type mappings, see Data type mappings.
    3. After you modify the data structures based on your business requirements, hold down the left mouse button to select an SQL statement and click Execute SQL Statement(F8).

      After the execution is successful, the execution result is displayed in the Execution Result section.

      Notice
      • Before you execute an SQL statement, you must select the SQL statement that you want to execute. Otherwise, the system executes the first SQL statement by default.
      • You cannot select multiple SQL statements to execute at the same time. If you select multiple SQL statements, the system reports an error.
      fig_result
  3. Execute the SELECT statement to query the required data.