Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 35 additions & 20 deletions src/UserGuide/Master/Table/Basic-Concept/Table-Management_apache.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,19 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)?
**Examples:**

```SQL
IoTDB> show tables from database1
show tables from database1;
```
```shell
+---------+---------------+
|TableName| TTL(ms)|
+---------+---------------+
| table1| 31536000000|
+---------+---------------+

IoTDB> show tables details from database1
```
```sql
show tables details from database1;
```
```shell
+---------------+-----------+------+-------+
| TableName| TTL(ms)|Status|Comment|
+---------------+-----------+------+-------+
Expand Down Expand Up @@ -162,7 +167,9 @@ Used to view column names, data types, categories, and states of a table.
**Examples:**

```SQL
IoTDB> desc table1
desc table1;
```
```shell
+------------+---------+---------+
| ColumnName| DataType| Category|
+------------+---------+---------+
Expand All @@ -177,8 +184,11 @@ IoTDB> desc table1
| status| BOOLEAN| FIELD|
|arrival_time|TIMESTAMP| FIELD|
+------------+---------+---------+

IoTDB> desc table1 details
```
```sql
desc table1 details;
```
```shell
+------------+---------+---------+------+------------+
| ColumnName| DataType| Category|Status| Comment|
+------------+---------+---------+------+------------+
Expand Down Expand Up @@ -215,7 +225,9 @@ SHOW CREATE TABLE <TABLE_NAME>
**Example:**

```SQL
IoTDB:database1> show create table table1
show create table table1;
```
```shell
+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table| Create Table|
+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Expand All @@ -232,12 +244,15 @@ Used to update a table, including adding or deleting columns and configuring tab
**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
| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment'
| COMMENT ON COLUMN tableName.column IS 'column_comment'
#addColumn;
ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition;
#dropColumn;
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier;
#setTableProperties;
// set TTL can use this;
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments;
| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment';
| COMMENT ON COLUMN tableName.column IS 'column_comment';
```

**Note::**
Expand All @@ -249,11 +264,11 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col
**Example:**

```SQL
ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'
ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'
ALTER TABLE table1 set properties TTL=3600
COMMENT ON TABLE table1 IS 'table1'
COMMENT ON COLUMN table1.a IS null
ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a';
ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b';
ALTER TABLE table1 set properties TTL=3600;
COMMENT ON TABLE table1 IS 'table1';
COMMENT ON COLUMN table1.a IS null;
```

### 1.6 Delete Tables
Expand All @@ -269,6 +284,6 @@ DROP TABLE (IF EXISTS)? <TABLE_NAME>
**Examples:**

```SQL
DROP TABLE table1
DROP TABLE database1.table1
DROP TABLE table1;
DROP TABLE database1.table1;
```
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,19 @@ SHOW TABLES (DETAILS)? ((FROM | IN) database_name)?
**Examples:**

```SQL
IoTDB> show tables from database1
show tables from database1;
```
```shell
+---------+---------------+
|TableName| TTL(ms)|
+---------+---------------+
| table1| 31536000000|
+---------+---------------+

IoTDB> show tables details from database1
```
```sql
show tables details from database1;
```
```shell
+---------------+-----------+------+-------+
| TableName| TTL(ms)|Status|Comment|
+---------------+-----------+------+-------+
Expand Down Expand Up @@ -162,7 +167,9 @@ Used to view column names, data types, categories, and states of a table.
**Examples:**

```SQL
IoTDB> desc table1
desc table1;
```
```shell
+------------+---------+---------+
| ColumnName| DataType| Category|
+------------+---------+---------+
Expand All @@ -177,8 +184,11 @@ IoTDB> desc table1
| status| BOOLEAN| FIELD|
|arrival_time|TIMESTAMP| FIELD|
+------------+---------+---------+

IoTDB> desc table1 details
```
```sql
desc table1 details;
```
```shell
+------------+---------+---------+------+------------+
| ColumnName| DataType| Category|Status| Comment|
+------------+---------+---------+------+------------+
Expand Down Expand Up @@ -214,7 +224,9 @@ SHOW CREATE TABLE <TABLE_NAME>
**Example:**

```SQL
IoTDB:database1> show create table table1
show create table table1;
```
```shell
+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table| Create Table|
+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Expand All @@ -231,12 +243,15 @@ Used to update a table, including adding or deleting columns and configuring tab
**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
| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment'
| COMMENT ON COLUMN tableName.column IS 'column_comment'
#addColumn;
ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? column=columnDefinition;
#dropColumn;
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName DROP COLUMN (IF EXISTS)? column=identifier;
#setTableProperties;
// set TTL can use this;
| ALTER TABLE (IF EXISTS)? tableName=qualifiedName SET PROPERTIES propertyAssignments;
| COMMENT ON TABLE tableName=qualifiedName IS 'table_comment';
| COMMENT ON COLUMN tableName.column IS 'column_comment';
```

**Note::**
Expand All @@ -248,11 +263,11 @@ ALTER TABLE (IF EXISTS)? tableName=qualifiedName ADD COLUMN (IF NOT EXISTS)? col
**Example:**

```SQL
ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a'
ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b'
ALTER TABLE table1 set properties TTL=3600
COMMENT ON TABLE table1 IS 'table1'
COMMENT ON COLUMN table1.a IS null
ALTER TABLE table1 ADD COLUMN IF NOT EXISTS a TAG COMMENT 'a';
ALTER TABLE table1 ADD COLUMN IF NOT EXISTS b FLOAT FIELD COMMENT 'b';
ALTER TABLE table1 set properties TTL=3600;
COMMENT ON TABLE table1 IS 'table1';
COMMENT ON COLUMN table1.a IS null;
```

### 1.6 Delete Tables
Expand All @@ -268,6 +283,6 @@ DROP TABLE (IF EXISTS)? <TABLE_NAME>
**Examples:**

```SQL
DROP TABLE table1
DROP TABLE database1.table1
DROP TABLE table1;
DROP TABLE database1.table1;
```
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ try (ITableSession session =
After execution, you can verify the table creation using the following command:

```SQL
IoTDB> desc table1
desc table1;
```
```shell
+-----------+---------+-----------+
| ColumnName| DataType| Category|
+-----------+---------+-----------+
Expand All @@ -131,9 +133,9 @@ It is possible to insert data for specific columns. Columns not specified will r
**Example:**

```SQL
INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1)
INSERT INTO table1(region, plant_id, device_id, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:37:00', 90.0, 35.1);

INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:38:00', 91.0)
INSERT INTO table1(region, plant_id, device_id, time, temperature) VALUES ('Hamburg', '1001', '100', '2025-11-26 13:38:00', 91.0);
```

### 1.4 Null Value Insertion
Expand All @@ -145,10 +147,10 @@ You can explicitly set `null` values for tag columns, attribute columns, and fie
Equivalent to the above partial column insertion.

```SQL
# Equivalent to the example above
INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1)
# Equivalent to the example above;
INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:37:00', 90.0, 35.1);

INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null)
INSERT INTO table1(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity) VALUES ('Hamburg', '1001', '100', null, null, '2025-11-26 13:38:00', 91.0, null);
```

If no tag columns are included, the system will automatically create a device with all tag column values set to `null`.
Expand All @@ -165,13 +167,13 @@ IoTDB supports inserting multiple rows of data in a single statement to improve
INSERT INTO table1
VALUES
('2025-11-26 13:37:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:37:34'),
('2025-11-26 13:38:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25')
('2025-11-26 13:38:00', 'Frankfurt', '1001', '100', 'A', '180', 90.0, 35.1, true, '2025-11-26 13:38:25');

INSERT INTO table1
(region, plant_id, device_id, model_id, maintenance, time, temperature, humidity, status, arrival_time)
VALUES
('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:37:00', 90.0, 35.1, true, '2025-11-26 13:37:34'),
('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25')
('Frankfurt', '1001', '100', 'A', '180', '2025-11-26 13:38:00', 90.0, 35.1, true, '2025-11-26 13:38:25');
```

#### Notes
Expand Down Expand Up @@ -201,7 +203,7 @@ Using the [sample data](../Reference/Sample-Data.md) as the data source, first c
sql

```sql
IoTDB:database1> CREATE TABLE target_table ( time TIMESTAMP TIME, region STRING TAG, device_id STRING TAG, temperature FLOAT FIELD );
CREATE TABLE target_table ( time TIMESTAMP TIME, region STRING TAG, device_id STRING TAG, temperature FLOAT FIELD );
Msg: The statement is executed successfully.
```

Expand All @@ -214,9 +216,13 @@ The `query` part is a direct `select ... from ...` query.
sql

```sql
IoTDB:database1> insert into target_table select time,region,device_id,temperature from table1 where region = 'Beijing'
insert into target_table select time,region,device_id,temperature from table1 where region = 'Beijing';
Msg: The statement is executed successfully.
IoTDB:database1> select * from target_table where region='Beijing'
```
```sql
select * from target_table where region='Beijing';
```
```shell
+-----------------------------+--------+-----------+-------------+
| time| region| device_id| temperature|
+-----------------------------+--------+-----------+-------------+
Expand All @@ -243,9 +249,13 @@ The `query` part uses the table reference syntax `table source_table`.
sql

```sql
IoTDB:database1> insert into target_table(time,device_id,temperature) table table3
insert into target_table(time,device_id,temperature) table table3;
Msg: The statement is executed successfully.
IoTDB:database1> select * from target_table where region is null
```
```sql
select * from target_table where region is null;
```
```shell
+-----------------------------+------+-----------+-------------+
| time|region| device_id| temperature|
+-----------------------------+------+-----------+-------------+
Expand All @@ -270,9 +280,13 @@ The `query` part is a parenthesized subquery.
sql

```sql
IoTDB:database1> insert into target_table (select t1.time, t1.region as region, t1.device_id as device_id, t1.temperature as temperature from table1 t1 where t1.time in (select t2.time from table2 t2 where t2.region = 'Shanghai'))
insert into target_table (select t1.time, t1.region as region, t1.device_id as device_id, t1.temperature as temperature from table1 t1 where t1.time in (select t2.time from table2 t2 where t2.region = 'Shanghai'));
Msg: The statement is executed successfully.
IoTDB:database1> select * from target_table where region = 'Shanghai'
```
```sql
select * from target_table where region = 'Shanghai';
```
```shell
+-----------------------------+---------+-----------+-------------+
| time| region| device_id| temperature|
+-----------------------------+---------+-----------+-------------+
Expand Down Expand Up @@ -339,13 +353,13 @@ INSERT INTO table1(time, device_id, s1) VALUES(NOW(), 'tag1', TO_OBJECT(TRUE, 0,
2. **Segmented write**

```SQL
-- First write: TO_OBJECT(FALSE, 0, X'696F')
-- First write: TO_OBJECT(FALSE, 0, X'696F');
INSERT INTO table1(time, device_id, s1) VALUES(1, 'tag1', TO_OBJECT(FALSE, 0, X'696F'));

-- Second write: TO_OBJECT(FALSE, 2, X'7464')
-- Second write: TO_OBJECT(FALSE, 2, X'7464');
INSERT INTO table1(time, device_id, s1) VALUES(1, 'tag1', TO_OBJECT(FALSE, 2, X'7464'));

-- Third write: TO_OBJECT(TRUE, 4, X'62')
-- Third write: TO_OBJECT(TRUE, 4, X'62');
INSERT INTO table1(time, device_id, s1) VALUES(1, 'tag1', TO_OBJECT(TRUE, 4, X'62'));
```

Expand Down Expand Up @@ -379,5 +393,5 @@ updateAssignment
**Example**:

```SQL
update table1 set b = a where substring(a, 1, 1) like '%'
update table1 set b = a where substring(a, 1, 1) like '%';
```
Loading
Loading