Managing tables and directories
Written by
Updated at October 30, 2023
This section describes how to create, edit, or delete tables and directories using the cloud management console.
To create a table, you need a database.
Creating a table
You can create a row-oriented table or a document table.
Row-oriented table
Document table
- In the management console
, go to the folder page and select Managed Service for YDB. - Select the database to create a table in.
- Go to the Navigation tab.
- Choose Create → Table on the right of the page.
- Configure the table settings:
- Table Name. Must be unique within the database.
- Table type:
Row table
.
- Add columns:
- Column Name. Must be unique within the table.
- Column data Type. Regardless of the data type, each column may contain a
NULL
value. - Primary key. Specify whether the column is part of the primary key. Primary indexes are automatically created based on the primary key.
- Set up secondary indexes
if needed.- Secondary index Name. Must be unique within the table.
- Key: One or more columns that make up a key for creating a secondary index.
- Set up the partitioning
policy.None
: The table is not partitioned.Evenly
: The entire range of values of Uint32 or Uint64 key columns (from 0 to the maximum value) is split into same-length intervals. When using this policy, set the number of intervals in the Count field.Explicitly
: Lets you explicitly specify values for keys that will act as boundaries for the initial partitioning of the table. To add another boundary value, click Add split point.
- Configure automatic partitioning:
- By size: If enabled, a partition is split into two when a certain data size is reached.
- By load: If enabled, a partition is split into two if it is under high loads for a certain period of time (uses a lot of CPU time).
- Configure advanced table settings:
- Auto-partitioning by size in MB: Threshold data size at which auto partitioning by size is triggered.
- Minimum number of partitions: Number of partitions in the table below which no partition merge by size or load is performed.
- Maximum number of partitions: Number of partitions in the table above which no splitting by size or load is performed.
- Bloom filter for primary key: If enabled, applies the Bloom filter
to search data by a key. In some cases, it can speed up key reads.
- Click Create table.
To create row-oriented tables, you can also use the CREATE TABLE
Note
Document tables are only available in Managed Service for YDB serverless mode.
- In the management console
, go to the folder page and select Managed Service for YDB. - Select the database to create a table in.
- Choose Create → Table on the right of the page.
- Configure the table settings:
- Table Name. Must be unique within the database.
- Table type:
Document table
.
- Add columns:
- Column Name. Must be unique within the table.
- Column data Type. Regardless of the data type, each column may contain a
NULL
value. - Partition key: A simple primary key that consists of a single attribute. YDB uses the partition key value as an input for the internal hashing function. The result of calculating the hash function determines the partition where the item will be stored.
- Sort key. A primary key can be composite and consist of a partition key and a sort key. All items with the same partition key will be stored together, in sorted order by the sort key value. If a partition key and a sort key are specified in a document table, two elements may contain the same value for the partition key, but must contain different values for the sort key.
- Click Create table.
Changing the table structure
In the YDB cloud console, you can add non-key columns to a table and change its automatic partitioning settings.
- In the management console
, go to the folder page and select Managed Service for YDB. - Select the database to update a table in.
- Find the table in the list and select
→ Edit. - Add new columns to the table and specify their parameters:
- Column Name. Must be unique within the table.
- Column data Type. Regardless of the data type, each column may contain a
NULL
value.
- To delete non-key columns from the table, click
in the appropriate line. You cannot delete columns that make up a primary key. - Configure automatic partitioning:
- By size: If enabled, a partition is split into two when a certain data size is reached.
- By load: If enabled, a partition is split into two if it is under high loads for a certain period of time (uses a lot of CPU time).
- Configure advanced table settings:
- Auto-partitioning by size in MB: Threshold data size at which auto partitioning by size is triggered.
- Minimum number of partitions: Number of partitions in the table below which no partition merge by size or load is performed.
- Maximum number of partitions: Number of partitions in the table above which no splitting by size or load is performed.
- Bloom filter for primary key: If enabled, applies the Bloom filter
to search data by a key. In some cases, it can speed up key reads.
- Click Alter table.
To alter row-oriented tables, you can also use the ALTER TABLE
Deleting tables
- In the management console
, go to the folder page and select Managed Service for YDB. - Select the database to delete a table from.
- Find the table in the list and select
→ Delete. - Confirm the deletion.
To drop row-oriented tables, you can also use the DROP TABLE
Creating and deleting directories
- In the management console
, go to the folder page and select Managed Service for YDB. - Select the database to create a directory in.
- Choose Create → Directory on the right of the page.
- Enter the directory name and click Create directory.