Updated on 2023-12-13 GMT+08:00

Creating a Table

A GaussDB(for MySQL) data table consists of basic information, columns, generated columns, indexes, and foreign keys, among which generated columns, indexes, and foreign keys are optional. Configure these items as required.

Procedure

  1. Log in to the management console.
  2. Click in the upper left corner and select a region and project.
  3. Click in the upper left corner, and under Databases, click Data Admin Service.
  4. In the navigation pane on the left, choose Development Tool.

    You can also click Go to Development Tool on the overview page.

  5. Locate the DB instance that you want to log in to and click Log In in the Operation column.
  6. On the top menu bar, choose Database Management. On the displayed Objects page, select Tables and click Create Table.
  7. On the displayed page, specify required parameters.

    Figure 1 Basic Information

  8. Click Advanced Settings, specify required parameters based on service requirements. These parameters are mandatory.

    Figure 2 Advanced settings

    To learn more about partitioned table, see the following note.

    Table partitioning is used to divide a large table into several small tables based on conditions. Different rows in the table can be allocated to different physical partitions. Creating a partitioned table is not recommended because there are many constraints on MySQL partitioned tables.

    If you need to create a partitioned table, you can create one by referring to the following example. The supported partitioning methods are RANGE, LIST, COLUMNS, KEY, and HASH.

    For example, if you want to create partitioned table employees, enter the following content for Partition Definition:

    Creating a partitioned table:

    CREATE TABLE employees (
    id INT NOT NULL,
    fname VARCHAR(30),
    lname VARCHAR(30),
    hired DATE NOT NULL DEFAULT '1970-01-01',
    separated DATE NOT NULL DEFAULT '9999-12-31',
    job_code INT NOT NULL,
    store_id INT NOT NULL
    )
    PARTITION BY RANGE (store_id) (
    PARTITION p0 VALUES LESS THAN (6),
    PARTITION p1 VALUES LESS THAN (11),
    PARTITION p2 VALUES LESS THAN (16),
    PARTITION p3 VALUES LESS THAN (21)
    );

    Specifying a partition definition:

    PARTITION BY RANGE (store_id) (
    PARTITION p0 VALUES LESS THAN (6),
    PARTITION p1 VALUES LESS THAN (11),
    PARTITION p2 VALUES LESS THAN (16),
    PARTITION p3 VALUES LESS THAN (21)
    )

  9. Click Next.
  10. On the Column page, click Add and set Column Name, Type, Length, Nullable, Primary Key, and Extended Information as needed.

    • If you do not need to add generated columns, indexes, or foreign keys, click Create at the bottom of the page. In the displayed SQL Preview dialog box, click Execute.
      Figure 3 Configuring fields
    • If you need to add generated columns, indexes, and foreign keys, click Next until all your desired parameters are specified. Configure required parameters and click Create.
    • The length of a column name is limited. Enter no more than 64 characters.
    • In the Type column, you can select only the parameters from the drop-down list box.
    • In the Length column, retain the default value. For some columns whose length is variable, you can change their lengths.
    • If Primary Key is selected, Nullable will be grayed out.
    • Auto Increment can be set for one column only. When it is selected, Primary Key must be selected, and no default values can be set.
    • When you create a foreign key, the type of columns in the referenced table must be the same as that of included columns, and must be the primary key or have a unique index.

  11. In the SQL Preview dialog box, click Execute.