diff --git a/src/UserGuide/Master/Table/Basic-Concept/Database-Management.md b/src/UserGuide/Master/Table/Basic-Concept/Database-Management.md new file mode 100644 index 000000000..78730f799 --- /dev/null +++ b/src/UserGuide/Master/Table/Basic-Concept/Database-Management.md @@ -0,0 +1,173 @@ + + +# Database Management + +## 1. Database Management + +### 1.1 Create a Database + +This command is used to create a database. + +**Syntax:** + +```SQL + CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +**Note: ** + +1. ``: The name of the database, with the following characteristics: + - Case-insensitive. + - Can include commas (`,`), underscores (`_`), numbers, letters, and Chinese characters. + - Maximum length is 64 characters. + - Names with special characters or Chinese characters must be enclosed in double quotes (`""`). + +2. `WITH properties`: Property names are case-insensitive and currently cannot be modified. For more details, refer to the case sensitivity rules [case-sensitivity](../SQL-Manual/Identifier.md#2-case-sensitivity)。Configurable properties include: + +| Property | Description | Default Value | +| ----------------------- | ------------------------------------------------------------ | -------------------- | +| TTL | Automatic data expiration time, in milliseconds | `INF` | +| TIME_PARTITION_INTERVAL | Time partition interval for the database, in milliseconds | `604800000` (7 days) | +| SCHEMA_REGION_GROUP_NUM | Number of metadata replica groups; generally does not require modification | `1` | +| DATA_REGION_GROUP_NUM | Number of data replica groups; generally does not require modification | `2` | + +**Examples:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +// Sets TTL to 1 year. +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 Use a Database + +Specify the current database as the namespace for table operations. + +**Syntax:** + +```SQL +USE +``` + +**Example:** + +```SQL +USE database1 +``` + +### 1.3 View the Current Database + +Displays the name of the currently connected database. If no USE statement has been executed, the default is `null`. + +**Syntax:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**Example:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 View All Databases + +Displays all databases and their properties. + +**Syntax:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +**Columns Explained:** + + +| Column Name | Description | +| ----------------------- | ------------------------------------------------------------ | +| database | Name of the database. | +| TTL | Data retention period. If TTL is specified when creating a database, it applies to all tables within the database. You can also set or update the TTL of individual tables using [create table](../Basic-Concept/Table-Management.md#11-create-a-table) 、[alter table](../Basic-Concept/Table-Management.md#14-update-tables) . | +| SchemaReplicationFactor | Number of metadata replicas, ensuring metadata high availability. This can be configured in the `iotdb-system.properties` file under the `schema_replication_factor` property. | +| DataReplicationFactor | Number of data replicas, ensuring data high availability. This can be configured in the `iotdb-system.properties` file under the `data_replication_factor` property. | +| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. | +| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). | + +**Examples:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 Update a Database + +Currently not supported; will be available after version 2.0.2.1. + +### 1.6 Delete a Database + +Deletes the specified database and all associated tables and data. + +**Syntax:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**Note:** + +1. A database currently in use can still be dropped. +2. Deleting a database removes all its tables and stored data. + +**Example:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` diff --git a/src/UserGuide/Master/Table/Basic-Concept/Table-Management.md b/src/UserGuide/Master/Table/Basic-Concept/Table-Management.md new file mode 100644 index 000000000..16a1cd825 --- /dev/null +++ b/src/UserGuide/Master/Table/Basic-Concept/Table-Management.md @@ -0,0 +1,289 @@ + + +# Table Management + +## 1. Table Management + +### 1.1 Create a Table + +#### 1.1.1 Manually create a table with CREATE + +Manually create a table within the current or specified database.The format is "database name. table name". + +**Syntax:** + +```SQL +CREATE TABLE (IF NOT EXISTS)? + '(' (columnDefinition (',' columnDefinition)*)? ')' + (WITH properties)? + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE) + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? + ; + +properties + : '(' propertyAssignments ')' + ; + +propertyAssignments + : property (',' property)* + ; + +property + : identifier EQ propertyValue + ; +``` + +**Note:** + +1. If the time column (`TIME`) is not specified, IoTDB automatically adds one. Other columns can be added using the `enable_auto_create_schema` configuration or session interface commands. +2. Column categories default to `FIELD` if not specified. `TAG` and `ATTRIBUTE` columns must be of type `STRING`. +3. Table `TTL` defaults to the database `TTL`. You can omit this property or set it to `default` if the default value is used. +4. ``: + 1. Case-insensitive. + 2. Can include special characters such as `~!`"`%`, etc. + 3. Names with special or Chinese characters must be enclosed in double quotes (`""`). + 4. Outer double quotes are not retained in the final table name. For example: `"a""b"` becomes `a"b`. +5. **`columnDefinition`**: Column names share the same characteristics as table names and can include special characters such as `.`. + +**Examples:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE, + temperature FLOAT FIELD, + humidity FLOAT FIELD, + status Boolean FIELD, + arrival_time TIMESTAMP FIELD +) WITH (TTL=31536000000); + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "Site" STRING TAG, + "Temperature" int32 FIELD + ) with (TTL=DEFAULT); +``` + +#### 1.1.2 Automatically Create Tables via SESSION + +Tables can be created automatically when inserting data via session. + +**Examples:** + +```Java +try (ITableSession session = + new TableSessionBuilder() + .nodeUrls(Collections.singletonList("127.0.0.1:6667")) + .username("root") + .password("root") + .build()) { + + session.executeNonQueryStatement("CREATE DATABASE db1"); + session.executeNonQueryStatement("use db1"); + + // Insert data without manually creating the table + List columnNameList = + Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); + List dataTypeList = + Arrays.asList( + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.FLOAT, + TSDataType.DOUBLE); + List columnTypeList = + new ArrayList<>( + Arrays.asList( + Tablet.ColumnCategory.TAG, + Tablet.ColumnCategory.TAG, + Tablet.ColumnCategory.TAG, + Tablet.ColumnCategory.ATTRIBUTE, + Tablet.ColumnCategory.FIELD, + Tablet.ColumnCategory.FIELD)); + Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); + for (long timestamp = 0; timestamp < 100; timestamp++) { + int rowIndex = tablet.getRowSize(); + tablet.addTimestamp(rowIndex, timestamp); + tablet.addValue("region_id", rowIndex, "1"); + tablet.addValue("plant_id", rowIndex, "5"); + tablet.addValue("device_id", rowIndex, "3"); + tablet.addValue("model", rowIndex, "A"); + tablet.addValue("temperature", rowIndex, 37.6F); + tablet.addValue("humidity", rowIndex, 111.1); + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { + session.insert(tablet); + tablet.reset(); + } + } + if (tablet.getRowSize() != 0) { + session.insert(tablet); + tablet.reset(); + } +} +``` + +After the code execution is complete, you can use the following statement to verify that the table has been successfully created, including details about the time column, tag columns, attribute columns, and field columns. + +```SQL +IoTDB> desc table1 ++-----------+---------+-----------+ +| ColumnName| DataType| Category| ++-----------+---------+-----------+ +| time|TIMESTAMP| TIME| +| region_id| STRING| TAG| +| plant_id| STRING| TAG| +| device_id| STRING| TAG| +| model| STRING| ATTRIBUTE| +|temperature| FLOAT| FIELD| +| humidity| DOUBLE| FIELD| ++-----------+---------+-----------+ +``` + +### 1.2 View Tables + +Used to view all tables and their properties in the current or a specified database. + +**Syntax:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**Note:** + +1. If the `FROM` or `IN` clause is specified, the command lists all tables in the specified database. +2. If neither `FROM` nor `IN` is specified, the command lists all tables in the currently selected database. If no database is selected (`USE` statement not executed), an error is returned. +3. When the `DETAILS` option is used, the command shows the current state of each table: + 1. `USING`: The table is available and operational. + 2. `PRE_CREATE`: The table is in the process of being created or the creation has failed; the table is not available. + 3. `PRE_DELETE`: The table is in the process of being deleted or the deletion has failed; the table will remain permanently unavailable. + +**Examples:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+ +|TableName|TTL(ms)| ++---------+-------+ +| test| INF| ++---------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+ +|TableName|TTL(ms)| Status| ++---------+-------+----------+ +| test| INF| USING| +| turbine| INF|PRE_CREATE| +| car| 1000|PRE_DELETE| ++---------+-------+----------+ +``` + +### 1.3 View Table Columns + +Used to view column names, data types, categories, and states of a table. + +**Syntax:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**Note:** If the `DETAILS` option is specified, detailed state information of the columns is displayed: + +- `USING`: The column is in normal use. +- `PRE_DELETE`: The column is being deleted or the deletion has failed; it is permanently unavailable. + + + +**Examples:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+ +|ColumnName| DataType| Category|d +| time|TIMESTAMP| TIME| +| a| STRING| TAG| +| b| STRING| ATTRIBUTE| +| c| INT32| FIELD| ++----------+---------+-----------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+ +|ColumnName| DataType| Category| Status| ++----------+---------+-----------+----------+ +| time|TIMESTAMP| TIME| USING| +| a| STRING| TAG| USING| +| b| STRING| ATTRIBUTE| USING| +| c| INT32| FIELD| USING| +| d| INT32| FIELD|PRE_DELETE| ++----------+---------+-----------+----------+ +``` + +### 1.4 Update Tables + +Used to update a table, including adding or deleting columns and configuring table properties. + +**Syntax:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +``` + +**Note::** + +1. The `SET PROPERTIES` operation currently only supports configuring the `TTL` property of a table +2. The delete column function only supports deleting the ATTRIBUTE and FILD columns, and the TAG column does not support deletion. + +**Example:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG +ALTER TABLE tableB set properties TTL=3600 +``` + +### 1.5 Delete Tables + +Used to delete a table. + +**Syntax:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` \ No newline at end of file diff --git a/src/UserGuide/latest-Table/Basic-Concept/Database-Management.md b/src/UserGuide/latest-Table/Basic-Concept/Database-Management.md new file mode 100644 index 000000000..78730f799 --- /dev/null +++ b/src/UserGuide/latest-Table/Basic-Concept/Database-Management.md @@ -0,0 +1,173 @@ + + +# Database Management + +## 1. Database Management + +### 1.1 Create a Database + +This command is used to create a database. + +**Syntax:** + +```SQL + CREATE DATABASE (IF NOT EXISTS)? (WITH properties)? +``` + +**Note: ** + +1. ``: The name of the database, with the following characteristics: + - Case-insensitive. + - Can include commas (`,`), underscores (`_`), numbers, letters, and Chinese characters. + - Maximum length is 64 characters. + - Names with special characters or Chinese characters must be enclosed in double quotes (`""`). + +2. `WITH properties`: Property names are case-insensitive and currently cannot be modified. For more details, refer to the case sensitivity rules [case-sensitivity](../SQL-Manual/Identifier.md#2-case-sensitivity)。Configurable properties include: + +| Property | Description | Default Value | +| ----------------------- | ------------------------------------------------------------ | -------------------- | +| TTL | Automatic data expiration time, in milliseconds | `INF` | +| TIME_PARTITION_INTERVAL | Time partition interval for the database, in milliseconds | `604800000` (7 days) | +| SCHEMA_REGION_GROUP_NUM | Number of metadata replica groups; generally does not require modification | `1` | +| DATA_REGION_GROUP_NUM | Number of data replica groups; generally does not require modification | `2` | + +**Examples:** + +```SQL +CREATE DATABASE database1; +CREATE DATABASE IF NOT EXISTS database1; + +// Sets TTL to 1 year. +CREATE DATABASE IF NOT EXISTS database1 with(TTL=31536000000); +``` + +### 1.2 Use a Database + +Specify the current database as the namespace for table operations. + +**Syntax:** + +```SQL +USE +``` + +**Example:** + +```SQL +USE database1 +``` + +### 1.3 View the Current Database + +Displays the name of the currently connected database. If no USE statement has been executed, the default is `null`. + +**Syntax:** + +```SQL +SHOW CURRENT_DATABASE +``` + +**Example:** + +```SQL +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| null| ++---------------+ + +IoTDB> USE test; + +IoTDB> SHOW CURRENT_DATABASE; ++---------------+ +|CurrentDatabase| ++---------------+ +| iot_database| ++---------------+ +``` + +### 1.4 View All Databases + +Displays all databases and their properties. + +**Syntax:** + +```SQL +SHOW DATABASES (DETAILS)? +``` + +**Columns Explained:** + + +| Column Name | Description | +| ----------------------- | ------------------------------------------------------------ | +| database | Name of the database. | +| TTL | Data retention period. If TTL is specified when creating a database, it applies to all tables within the database. You can also set or update the TTL of individual tables using [create table](../Basic-Concept/Table-Management.md#11-create-a-table) 、[alter table](../Basic-Concept/Table-Management.md#14-update-tables) . | +| SchemaReplicationFactor | Number of metadata replicas, ensuring metadata high availability. This can be configured in the `iotdb-system.properties` file under the `schema_replication_factor` property. | +| DataReplicationFactor | Number of data replicas, ensuring data high availability. This can be configured in the `iotdb-system.properties` file under the `data_replication_factor` property. | +| TimePartitionInterval | Time partition interval, determining how often data is grouped into directories on disk. The default is typically one week. | +| Model | Returned when using the `DETAILS` option, showing the data model corresponding to each database (e.g., timeseries tree model or device table model). | + +**Examples:** + +```SQL +IoTDB> show databases ++---------+-------+-----------------------+---------------------+---------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval| ++---------+-------+-----------------------+---------------------+---------------------+ +|test_prop| 300| 3| 2| 100000| +| test2| 300| 3| 2| 604800000| ++---------+-------+-----------------------+---------------------+---------------------+ +IoTDB> show databases details ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +| Database|TTL(ms)|SchemaReplicationFactor|DataReplicationFactor|TimePartitionInterval|SchemaRegionGroupNum| DataRegionGroupNum| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +|test_prop| 300| 3| 2| 100000| 1| 2| +| test2| 300| 3| 2| 604800000| 1| 2| ++---------+-------+-----------------------+---------------------+---------------------+-----------------------+-----------------------+ +``` + +### 1.5 Update a Database + +Currently not supported; will be available after version 2.0.2.1. + +### 1.6 Delete a Database + +Deletes the specified database and all associated tables and data. + +**Syntax:** + +```SQL +DROP DATABASE (IF EXISTS)? +``` + +**Note:** + +1. A database currently in use can still be dropped. +2. Deleting a database removes all its tables and stored data. + +**Example:** + +```SQL +DROP DATABASE IF EXISTS database1 +``` diff --git a/src/UserGuide/latest-Table/Basic-Concept/Table-Management.md b/src/UserGuide/latest-Table/Basic-Concept/Table-Management.md new file mode 100644 index 000000000..16a1cd825 --- /dev/null +++ b/src/UserGuide/latest-Table/Basic-Concept/Table-Management.md @@ -0,0 +1,289 @@ + + +# Table Management + +## 1. Table Management + +### 1.1 Create a Table + +#### 1.1.1 Manually create a table with CREATE + +Manually create a table within the current or specified database.The format is "database name. table name". + +**Syntax:** + +```SQL +CREATE TABLE (IF NOT EXISTS)? + '(' (columnDefinition (',' columnDefinition)*)? ')' + (WITH properties)? + +columnDefinition + : identifier columnCategory=(TAG | ATTRIBUTE) + | identifier type (columnCategory=(TAG | ATTRIBUTE | TIME | FIELD))? + ; + +properties + : '(' propertyAssignments ')' + ; + +propertyAssignments + : property (',' property)* + ; + +property + : identifier EQ propertyValue + ; +``` + +**Note:** + +1. If the time column (`TIME`) is not specified, IoTDB automatically adds one. Other columns can be added using the `enable_auto_create_schema` configuration or session interface commands. +2. Column categories default to `FIELD` if not specified. `TAG` and `ATTRIBUTE` columns must be of type `STRING`. +3. Table `TTL` defaults to the database `TTL`. You can omit this property or set it to `default` if the default value is used. +4. ``: + 1. Case-insensitive. + 2. Can include special characters such as `~!`"`%`, etc. + 3. Names with special or Chinese characters must be enclosed in double quotes (`""`). + 4. Outer double quotes are not retained in the final table name. For example: `"a""b"` becomes `a"b`. +5. **`columnDefinition`**: Column names share the same characteristics as table names and can include special characters such as `.`. + +**Examples:** + +```SQL +CREATE TABLE table1 ( + time TIMESTAMP TIME, + region STRING TAG, + plant_id STRING TAG, + device_id STRING TAG, + model_id STRING ATTRIBUTE, + maintenance STRING ATTRIBUTE, + temperature FLOAT FIELD, + humidity FLOAT FIELD, + status Boolean FIELD, + arrival_time TIMESTAMP FIELD +) WITH (TTL=31536000000); + +CREATE TABLE if not exists table2 (); + +CREATE TABLE tableC ( + "Site" STRING TAG, + "Temperature" int32 FIELD + ) with (TTL=DEFAULT); +``` + +#### 1.1.2 Automatically Create Tables via SESSION + +Tables can be created automatically when inserting data via session. + +**Examples:** + +```Java +try (ITableSession session = + new TableSessionBuilder() + .nodeUrls(Collections.singletonList("127.0.0.1:6667")) + .username("root") + .password("root") + .build()) { + + session.executeNonQueryStatement("CREATE DATABASE db1"); + session.executeNonQueryStatement("use db1"); + + // Insert data without manually creating the table + List columnNameList = + Arrays.asList("region_id", "plant_id", "device_id", "model", "temperature", "humidity"); + List dataTypeList = + Arrays.asList( + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.STRING, + TSDataType.FLOAT, + TSDataType.DOUBLE); + List columnTypeList = + new ArrayList<>( + Arrays.asList( + Tablet.ColumnCategory.TAG, + Tablet.ColumnCategory.TAG, + Tablet.ColumnCategory.TAG, + Tablet.ColumnCategory.ATTRIBUTE, + Tablet.ColumnCategory.FIELD, + Tablet.ColumnCategory.FIELD)); + Tablet tablet = new Tablet("table1", columnNameList, dataTypeList, columnTypeList, 100); + for (long timestamp = 0; timestamp < 100; timestamp++) { + int rowIndex = tablet.getRowSize(); + tablet.addTimestamp(rowIndex, timestamp); + tablet.addValue("region_id", rowIndex, "1"); + tablet.addValue("plant_id", rowIndex, "5"); + tablet.addValue("device_id", rowIndex, "3"); + tablet.addValue("model", rowIndex, "A"); + tablet.addValue("temperature", rowIndex, 37.6F); + tablet.addValue("humidity", rowIndex, 111.1); + if (tablet.getRowSize() == tablet.getMaxRowNumber()) { + session.insert(tablet); + tablet.reset(); + } + } + if (tablet.getRowSize() != 0) { + session.insert(tablet); + tablet.reset(); + } +} +``` + +After the code execution is complete, you can use the following statement to verify that the table has been successfully created, including details about the time column, tag columns, attribute columns, and field columns. + +```SQL +IoTDB> desc table1 ++-----------+---------+-----------+ +| ColumnName| DataType| Category| ++-----------+---------+-----------+ +| time|TIMESTAMP| TIME| +| region_id| STRING| TAG| +| plant_id| STRING| TAG| +| device_id| STRING| TAG| +| model| STRING| ATTRIBUTE| +|temperature| FLOAT| FIELD| +| humidity| DOUBLE| FIELD| ++-----------+---------+-----------+ +``` + +### 1.2 View Tables + +Used to view all tables and their properties in the current or a specified database. + +**Syntax:** + +```SQL +SHOW TABLES (DETAILS)? ((FROM | IN) database_name)? +``` + +**Note:** + +1. If the `FROM` or `IN` clause is specified, the command lists all tables in the specified database. +2. If neither `FROM` nor `IN` is specified, the command lists all tables in the currently selected database. If no database is selected (`USE` statement not executed), an error is returned. +3. When the `DETAILS` option is used, the command shows the current state of each table: + 1. `USING`: The table is available and operational. + 2. `PRE_CREATE`: The table is in the process of being created or the creation has failed; the table is not available. + 3. `PRE_DELETE`: The table is in the process of being deleted or the deletion has failed; the table will remain permanently unavailable. + +**Examples:** + +```SQL +IoTDB> show tables from test_db ++---------+-------+ +|TableName|TTL(ms)| ++---------+-------+ +| test| INF| ++---------+-------+ + +IoTDB> show tables details from test_db ++---------+-------+----------+ +|TableName|TTL(ms)| Status| ++---------+-------+----------+ +| test| INF| USING| +| turbine| INF|PRE_CREATE| +| car| 1000|PRE_DELETE| ++---------+-------+----------+ +``` + +### 1.3 View Table Columns + +Used to view column names, data types, categories, and states of a table. + +**Syntax:** + +```SQL +(DESC | DESCRIBE) (DETAILS)? +``` + +**Note:** If the `DETAILS` option is specified, detailed state information of the columns is displayed: + +- `USING`: The column is in normal use. +- `PRE_DELETE`: The column is being deleted or the deletion has failed; it is permanently unavailable. + + + +**Examples:** + +```SQL +IoTDB> desc tableB ++----------+---------+-----------+ +|ColumnName| DataType| Category|d +| time|TIMESTAMP| TIME| +| a| STRING| TAG| +| b| STRING| ATTRIBUTE| +| c| INT32| FIELD| ++----------+---------+-----------+ + +IoTDB> desc tableB details ++----------+---------+-----------+----------+ +|ColumnName| DataType| Category| Status| ++----------+---------+-----------+----------+ +| time|TIMESTAMP| TIME| USING| +| a| STRING| TAG| USING| +| b| STRING| ATTRIBUTE| USING| +| c| INT32| FIELD| USING| +| d| INT32| FIELD|PRE_DELETE| ++----------+---------+-----------+----------+ +``` + +### 1.4 Update Tables + +Used to update a table, including adding or deleting columns and configuring table properties. + +**Syntax:** + +```SQL +ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition #addColumn +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier #dropColumn +// set TTL can use this +| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments #setTableProperties +``` + +**Note::** + +1. The `SET PROPERTIES` operation currently only supports configuring the `TTL` property of a table +2. The delete column function only supports deleting the ATTRIBUTE and FILD columns, and the TAG column does not support deletion. + +**Example:** + +```SQL +ALTER TABLE tableB ADD COLUMN IF NOT EXISTS a TAG +ALTER TABLE tableB set properties TTL=3600 +``` + +### 1.5 Delete Tables + +Used to delete a table. + +**Syntax:** + +```SQL +DROP TABLE (IF EXISTS)? +``` + +**Examples:** + +```SQL +DROP TABLE tableA +DROP TABLE test.tableB +``` \ No newline at end of file diff --git a/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management.md b/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management.md index 4806f6996..842de6137 100644 --- a/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management.md +++ b/src/zh/UserGuide/Master/Table/Basic-Concept/Database-Management.md @@ -123,7 +123,7 @@ SHOW DATABASES (DETAILS)? | 列名 | 含义 | | ----------------------- | ------------------------------------------------------------ | | database | database名称。 | -| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](#创建表) 、[alter table](#修改表) 来设置或更新表的TTL时间。 | +| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](../Basic-Concept/Table-Management.md#11-创建表) 、[alter table](../Basic-Concept/Table-Management.md#14-修改表) 来设置或更新表的TTL时间。 | | SchemaReplicationFactor | 元数据副本数,用于确保元数据的高可用性。可以在`iotdb-system.properties`中修改`schema_replication_factor`配置项。 | | DataReplicationFactor | 数据副本数,用于确保数据的高可用性。可以在`iotdb-system.properties`中修改`data_replication_factor`配置项。 | | TimePartitionInterval | 时间分区间隔,决定了数据在磁盘上按多长时间进行目录分组,通常采用默认1周即可。 | diff --git a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management.md b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management.md index 4806f6996..842de6137 100644 --- a/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management.md +++ b/src/zh/UserGuide/latest-Table/Basic-Concept/Database-Management.md @@ -123,7 +123,7 @@ SHOW DATABASES (DETAILS)? | 列名 | 含义 | | ----------------------- | ------------------------------------------------------------ | | database | database名称。 | -| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](#创建表) 、[alter table](#修改表) 来设置或更新表的TTL时间。 | +| TTL | 数据保留周期。如果在创建数据库的时候指定TTL,则TTL对该数据库下所有表的TTL生效。也可以再通过 [create table](../Basic-Concept/Table-Management.md#11-创建表) 、[alter table](../Basic-Concept/Table-Management.md#14-修改表) 来设置或更新表的TTL时间。 | | SchemaReplicationFactor | 元数据副本数,用于确保元数据的高可用性。可以在`iotdb-system.properties`中修改`schema_replication_factor`配置项。 | | DataReplicationFactor | 数据副本数,用于确保数据的高可用性。可以在`iotdb-system.properties`中修改`data_replication_factor`配置项。 | | TimePartitionInterval | 时间分区间隔,决定了数据在磁盘上按多长时间进行目录分组,通常采用默认1周即可。 |