Managing tables and directories
This section describes how to manage row-oriented and document tables as well as directories using the cloud management console or Terraform.
You can do the following:
To work with tables and directories, you will need a database.
Creating a table
You can create a row-oriented table or a document table.
Row-oriented table
- In the management console
, navigate to the folder page. - Go to Managed Service for YDB.
- Select the database to create your table in.
- Navigate to the Navigation tab.
- Select Create → Table on the right side of the page.
- Configure the table:
- 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
NULLvalue. - 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.
- Configure 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 partitions. When using this policy, set the number of partitions in the Count field.Explicitly: Allows you to explicitly specify values for keys that will act as split points for initial table partitioning. To add another split point, click Add split point.
- Configure automatic partitioning:
- By size: If enabled, a partition is split into two when it reaches a certain data size.
- By load: If enabled, a partition is split into two if it receives high throughput (uses a lot of CPU time) for a certain period of time.
- Specify advanced table settings:
- Auto-partitioning by size in MB: Data size threshold that triggers auto-partitioning by size.
- Minimum number of partitions: Number of partitions in the table below which no partitions are merged by size or load.
- Maximum number of partitions: Number of partitions in the table above which no partitions are split by size or load.
- Bloom filter for primary key: If enabled, YDB uses a Bloom filter
to search data by 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
To learn how to create a row-oriented table using Terraform, see Creating row-oriented and column-oriented tables in a database.
Document table
Note
Document tables are only available in Managed Service for YDB serverless mode.
- In the management console
, navigate to the folder page. - Go to Managed Service for YDB.
- Select the database to create your table in.
- Select Create → Table on the right side of the page.
- Configure the table:
- 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
NULLvalue. - Partition key: Simple primary key that consists of one attribute. YDB uses a partition key as an input for internal hashing. The hashing function result determines the partition the element will be stored in.
- Sort key. A primary key can be composite and consist of a partition key and a sort key. All elements sharing the partition key will be stored together and sorted according to their sort key value. In a document table that has both a partition key and a sort key, any two elements may share the partition key value but must have different sort key values.
- Click Create table.
You can learn how to create a document table using Terraform in Creating document tables in a database.
Column-oriented table
- In the management console
, navigate to the folder page. - Go to Managed Service for YDB.
- Select the database to create your table in.
- Navigate to the Navigation tab.
- Select Create → Table on the right side of the page.
- Configure the table:
- Table Name must be unique within the database.
- Table type:
Column table.
- Add columns:
-
Column Name must be unique within the table.
-
Column data Type.
-
Primary key. Specify whether the column is part of the primary key. Primary indexes are automatically created based on the primary key.
Note
The column order in the primary key depends on the column order in the table you are creating.
-
NOT NULL constraint. Specify whether the column may contain a
NULLvalue.
-
- Configure the table TTL parameters:
- Column. Select the column whose value will be used to calculate the lifetime of rows.
- Lifetime. Specify the lifetime of table rows.
- Unit. Select the measurement unit for the table row lifetime you specified.
- Configure partitioning:
- Partition key: Specify the column to split the table by.
- Partition count: Specify the number of partitions for the table.
- Click Create table.
To create column-oriented tables, you can also use the CREATE TABLE
You can learn how to create a column-oriented table using Terraform in Creating row-oriented and column-oriented tables in a database.
Changing the table schema
Row-oriented table
In the YDB cloud console, you can add non-key columns to a table and change its automatic partitioning settings.
- In the management console
, navigate to the folder page. - Go to 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
NULLvalue.
- To delete non-key columns from the table, click
in the relevant row. You cannot delete columns that make up a primary key. - Configure automatic partitioning:
- By size: If enabled, a partition is split into two when it reaches a certain data size.
- By load: If enabled, a partition is split into two if it receives high throughput (uses a lot of CPU time) for a certain period of time.
- Specify advanced table settings:
- Auto-partitioning by size in MB: Data size threshold that triggers auto-partitioning by size.
- Minimum number of partitions: Number of partitions in the table below which no partitions are merged by size or load.
- Maximum number of partitions: Number of partitions in the table above which no partitions are split by size or load.
- Bloom filter for primary key: If enabled, YDB uses a Bloom filter
to search data by key. In some cases, it can speed up key reads.
- Click Alter table.
Learn more about the table entities you can change using Terraform in Creating row-oriented and column-oriented tables in a database.
Document table
Note
Currently, you can only add new rows to a table, without any preview in the management console.
- In the management console
, navigate to the folder page. - Go to Managed Service for YDB.
- Select the database to update a table in.
- Find the table in the list and click it.
- Click Add row.
- Enter the values for the columns listed in the form, then click Add.
Learn more about the table entities you can change using Terraform in Creating document tables in a database.
To edit row-oriented tables, you can also use the ALTER TABLE
Column-oriented table
-
In the management console
, navigate to the folder page. -
Go to Managed Service for YDB.
-
Select the database to update a table in.
-
Find the table in the list and select
→ Edit.Update the table schema as needed. You can do the following:
- 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
NULLvalue.
- To delete non-key columns from the table, click
in the relevant row. You cannot delete columns that make up a primary key. - Configure the table TTL parameters:
- Column. Select the column whose value will be used to calculate the lifetime of rows.
- Lifetime. Specify the lifetime of table rows.
- Unit. Select the measurement unit for the table row lifetime you specified.
- Add new columns to the table and specify their parameters:
-
Click Alter table.
To update column-oriented tables, you can also use the ALTER TABLE
Learn more about the table entities you can change using Terraform in Creating row-oriented and column-oriented tables in a database.
Note
Updating the store and partition_by parameters of the column-oriented table will result in recreating the table.
Deleting a table
Row-oriented table
- In the management console
, navigate to the folder page. - Go to Managed Service for YDB.
- Select the database to delete your table from.
- Find the table in the list and select
→ Delete. - Confirm the deletion.
To delete a row-oriented table, delete the yandex_ydb_table resource.
Document table
- In the management console
, navigate to the folder page. - Go to Managed Service for YDB.
- Navigate to the database to delete your document table from.
- Select the document table from the list, then click
→ Delete. - Confirm the deletion.
To delete a document table, delete the aws_dynamodb_table resource.
Column-oriented table
- In the management console
, navigate to the folder page. - Go to Managed Service for YDB.
- Select the database to delete your table from.
- Find the table in the list and select
→ Delete. - Confirm the deletion.
To delete a column-oriented table, delete the yandex_ydb_table resource.
To delete tables, you can also use the DROP TABLE
Creating and deleting directories
- In the management console
, navigate to the folder page. - Go to Managed Service for YDB.
- Select the database to create a directory in.
- Select Create → Directory on the right side of the page.
- Enter a name for your directory and click Create directory.