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
9 changes: 6 additions & 3 deletions src/.vuepress/sidebar/V2.0.x/en-Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ export const enSidebar = {
collapsible: true,
prefix: 'SQL-Manual/',
children: [
{ text: 'Identifier', link: 'Identifier' },
{ text: 'Keywords', link: 'Keywords' },
{ text: 'Metadata Operations', link: 'SQL-Metadata-Operations' },
{ text: 'Data Addition&Deletion', link: 'SQL-Data-Addition-Deletion' },
{
text: 'Query statement',
text: 'Data Query',
collapsible: true,
children: [
{ text: 'overview', link: 'overview' },
Expand All @@ -213,6 +213,9 @@ export const enSidebar = {
{ text: 'Nested Queries', link: 'Nested-Queries' },
],
},
{ text: 'Maintenance Statements', link: 'SQL-Maintenance-Statements' },
{ text: 'Identifier', link: 'Identifier' },
{ text: 'Keywords', link: 'Keywords' },
{
text: 'Functions and Operators',
collapsible: true,
Expand Down
9 changes: 6 additions & 3 deletions src/.vuepress/sidebar/V2.0.x/zh-Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ export const zhSidebar = {
collapsible: true,
prefix: 'SQL-Manual/',
children: [
{ text: '标识符', link: 'Identifier' },
{ text: '保留字&关键字', link: 'Keywords' },
{ text: '元数据操作', link: 'SQL-Metadata-Operations' },
{ text: '数据增删', link: 'SQL-Data-Addition-Deletion' },
{
text: '查询语句',
text: '数据查询',
collapsible: true,
children: [
{ text: '概览', link: 'overview' },
Expand All @@ -203,6 +203,9 @@ export const zhSidebar = {
{ text: '嵌套查询', link: 'Nested-Queries' },
],
},
{ text: '运维语句', link: 'SQL-Maintenance-Statements' },
{ text: '标识符', link: 'Identifier' },
{ text: '保留字&关键字', link: 'Keywords' },
{
text: '函数与操作符',
collapsible: true,
Expand Down
9 changes: 6 additions & 3 deletions src/.vuepress/sidebar_timecho/V2.0.x/en-Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ export const enSidebar = {
collapsible: true,
prefix: 'SQL-Manual/',
children: [
{ text: 'Identifier', link: 'Identifier' },
{ text: 'Keywords', link: 'Keywords' },
{ text: 'Metadata Operations', link: 'SQL-Metadata-Operations' },
{ text: 'Data Addition&Deletion', link: 'SQL-Data-Addition-Deletion' },
{
text: 'Query statement',
text: 'Data Query',
collapsible: true,
children: [
{ text: 'overview', link: 'overview' },
Expand All @@ -218,6 +218,9 @@ export const enSidebar = {
{ text: 'Nested Queries', link: 'Nested-Queries' },
],
},
{ text: 'Maintenance Statements', link: 'SQL-Maintenance-Statements' },
{ text: 'Identifier', link: 'Identifier' },
{ text: 'Keywords', link: 'Keywords' },
{
text: 'Functions and Operators',
collapsible: true,
Expand Down
9 changes: 6 additions & 3 deletions src/.vuepress/sidebar_timecho/V2.0.x/zh-Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ export const zhSidebar = {
collapsible: true,
prefix: 'SQL-Manual/',
children: [
{ text: '标识符', link: 'Identifier' },
{ text: '保留字&关键字', link: 'Keywords' },
{ text: '元数据操作', link: 'SQL-Metadata-Operations' },
{ text: '数据增删', link: 'SQL-Data-Addition-Deletion' },
{
text: '查询语句',
text: '数据查询',
collapsible: true,
children: [
{ text: '概览', link: 'overview' },
Expand All @@ -207,6 +207,9 @@ export const zhSidebar = {
{ text: '嵌套查询', link: 'Nested-Queries' },
],
},
{ text: '运维语句', link: 'SQL-Maintenance-Statements' },
{ text: '标识符', link: 'Identifier' },
{ text: '保留字&关键字', link: 'Keywords' },
{
text: '函数与操作符',
collapsible: true,
Expand Down
160 changes: 160 additions & 0 deletions src/UserGuide/Master/Table/SQL-Manual/SQL-Data-Addition-Deletion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<!--

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

-->

# Data Addition & Deletion

## 1. Data Insertion

**Syntax:**

```SQL
INSERT INTO <TABLE_NAME> [(COLUMN_NAME[, COLUMN_NAME]*)]? VALUES (COLUMN_VALUE[, COLUMN_VALUE]*)
```

[Detailed syntax reference](../Basic-Concept/Write-Updata-Data.md#_1-1-syntax)

**Example 1: Specified Columns Insertion**

```SQL
INSERT INTO table1("Region", "PlantID", "DeviceID", Time, "Temperature", "Displacement")
VALUES ('Hunan', '3001', '3', 4, 90.0, 1200.0);

INSERT INTO table1("Region", "PlantID", "DeviceID", Time, "Temperature")
VALUES ('Hunan', '3001', '3', 5, 90.0);
```

**Example 2: NULL Value Insertion**

```SQL
-- Equivalent to partial insertion with NULL values
INSERT INTO table1("Region", "PlantID", "DeviceID", "Model", "MaintenanceCycle", Time, "Temperature", "Displacement")
VALUES ('Hunan', '3001', '3', NULL, NULL, 4, 90.0, 1200.0);

INSERT INTO table1("Region", "PlantID", "DeviceID", "Model", "MaintenanceCycle", Time, "Temperature", "Displacement")
VALUES ('Hunan', '3001', '3', NULL, NULL, 5, 90.0, NULL);
```

**Example 3: Multi-row Insertion**

```SQL
INSERT INTO table1 VALUES
('Beijing', '3001', '3', '1', '10', 4, 90.0, 1200.0),
('Beijing', '3001', '3', '1', '10', 5, 90.0, 1200.0);

INSERT INTO table1("Region", "PlantID", "DeviceID", Time, "Temperature", "Displacement")
VALUES
('Beijing', '3001', '3', 4, 90.0, 1200.0),
('Beijing', '3001', '3', 5, 90.0, 1200.0);
```

## 2. Data Update

**Syntax:**

```SQL
UPDATE <TABLE_NAME> SET updateAssignment (',' updateAssignment)* (WHERE where=booleanExpression)?

updateAssignment
: identifier EQ expression
;
```

[Detailed syntax reference](../Basic-Concept/Write-Updata-Data.md#_2-1-syntax)

**Example:**

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

## 3. Data Deletion

**Syntax:**

```SQL
DELETE FROM <TABLE_NAME> [WHERE_CLAUSE]?

WHERE_CLAUSE:
WHERE DELETE_CONDITION

DELETE_CONDITION:
SINGLE_CONDITION
| DELETE_CONDITION AND DELETE_CONDITION
| DELETE_CONDITION OR DELETE_CONDITION

SINGLE_CODITION:
TIME_CONDITION | ID_CONDITION

TIME_CONDITION:
time TIME_OPERATOR LONG_LITERAL

TIME_OPERATOR:
< | > | <= | >= | =

ID_CONDITION:
identifier = STRING_LITERAL
```

**Example 1: Full Table Deletion**

```SQL
DELETE FROM table1
```

**Example 2: Time-range Deletion**

```SQL
-- Single time range
DELETE FROM table1 WHERE time <= 2024-11-29 00:00:00

-- Multiple time ranges
DELETE FROM table1 WHERE time >= 2024-11-27 00:00:00 and time <= 2024-11-29 00:00:00
```

**Example 3: Device-Specific Deletion**

```SQL
-- Delete data for specific device
DELETE FROM table1
WHERE device_id='101' AND model_id = 'B';

-- Delete data for device within time range
DELETE FROM table1
WHERE time >= '2024-11-27 16:39:00' AND time <= '2024-11-29 16:42:00'
AND device_id='101' AND model_id = 'B';

-- Delete data for specific device model
DELETE FROM table1 WHERE model_id = 'B';
```

## 4. Device Deletion

**Syntax:**

```SQL
DELETE DEVICES FROM tableName=qualifiedName (WHERE booleanExpression)?
```

**Example: Delete specified device and all associated data**

```SQL
DELETE DEVICES FROM table1 WHERE device_id = '101'
```
Loading