Creating a Table
A TaurusDB database table consists of basic information, columns, generated columns, indexes, and foreign keys, among which generated columns, indexes, and foreign keys are optional.
Procedure
- Log in to the DAS console.
- Click in the upper left corner and select a region and project.
- Click in the upper left corner, and under Databases, click Data Admin Service.
- In the navigation pane on the left, choose Development Tool.
You can also click Go to Development Tool on the overview page.
- Locate the DB instance that you want to log in to and click Log In in the Operation column.
- On the top menu bar, choose Database Management. On the displayed Objects page, select Tables and click Create Table.
- On the displayed page, specify required parameters.
Figure 1 Basic Information
- 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) )
- Click Next.
- 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.
- 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.
- In the SQL Preview dialog box, click Execute.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot