From e0b58b0325892b15eb5a34f6c42247029757f025 Mon Sep 17 00:00:00 2001 From: CookiePieWw Date: Thu, 21 Nov 2024 14:40:50 +0800 Subject: [PATCH] docs: refine --- docs/reference/sql/alter.md | 52 +++++++++++-------- .../current/reference/sql/alter.md | 43 +++++++++------ 2 files changed, 59 insertions(+), 36 deletions(-) diff --git a/docs/reference/sql/alter.md b/docs/reference/sql/alter.md index aba905c61..4f12c02bf 100644 --- a/docs/reference/sql/alter.md +++ b/docs/reference/sql/alter.md @@ -7,31 +7,22 @@ * Rename a table * Modify table options -## Syntax +## ALTER DATABASE + +### Syntax ```sql ALTER DATABASE db [SET = [, ...] | UNSET [, ...] ] - -ALTER TABLE [db.]table - [ADD COLUMN name type [options] - | DROP COLUMN name - | MODIFY COLUMN name type - | MODIFY COLUMN name SET FULLTEXT [WITH ] - | MODIFY COLUMN name UNSET FULLTEXT - | RENAME name - | SET = [, ...] - | UNSET [, ...] - ] ``` -## Examples +### Examples -### Modify database options +#### Modify database options -`ALTER DATABASE` statements can be used to change the options of databases. +`ALTER DATABASE` statements can be used to modify the options of databases. Currently following options are supported: - `ttl`: the default retention time of data in database. @@ -48,7 +39,26 @@ Remove the default retention time of data in the database: ALTER DATABASE db UNSET 'ttl'; ``` -### Add column +## ALTER TABLE + +### Syntax + +```sql +ALTER TABLE [db.]table + [ADD COLUMN name type [options] + | DROP COLUMN name + | MODIFY COLUMN name type + | MODIFY COLUMN name SET FULLTEXT [WITH ] + | MODIFY COLUMN name UNSET FULLTEXT + | RENAME name + | SET = [, ...] + | UNSET [, ...] + ] +``` + +### Examples + +#### Add column Adds a new column to the table: @@ -75,7 +85,7 @@ Adds a new column as a tag(primary key) with a default value: ALTER TABLE monitor ADD COLUMN app STRING DEFAULT 'shop' PRIMARY KEY; ``` -### Remove column +#### Remove column Removes a column from the table: @@ -85,7 +95,7 @@ ALTER TABLE monitor DROP COLUMN load_15; The removed column can't be retrieved immediately by all subsequent queries. -### Modify column type +#### Modify column type Modify the date type of a column @@ -95,7 +105,7 @@ ALTER TABLE monitor MODIFY COLUMN load_15 STRING; The modified column cannot be a tag (primary key) or time index, and it must be nullable to ensure that the data can be safely converted (returns `NULL` on cast failures). -### Alter table options +#### Alter table options `ALTER TABLE` statements can also be used to change the options of tables. @@ -130,7 +140,7 @@ ALTER TABLE monitor SET 'compaction.twcs.max_inactive_window_runs'='6'; ALTER TABLE monitor UNSET 'ttl'; ``` -### Modify column fulltext index options +#### Modify column fulltext index options Enable fulltext index on a column: @@ -155,7 +165,7 @@ The column must be a string type to alter the fulltext index. If the fulltext index has never been enabled, you can enable it and specify the `analyzer` and `case_sensitive` options. When the fulltext index is already enabled on a column, you can disable it but **cannot modify the options**. -### Rename table +#### Rename table Renames the table: diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md index ddddf5003..cd8712a6e 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md @@ -7,14 +7,11 @@ * 重命名表 * 修改表选项 -## Syntax +## ALTER DATABASE -```sql -ALTER DATABASE db - [SET = [, ...] - | UNSET [, ...] - ] +### 语法 +```sql ALTER TABLE [db.]table [ADD COLUMN name type [options] | DROP COLUMN name @@ -26,9 +23,9 @@ ALTER TABLE [db.]table ] ``` -## 示例 +### 示例 -### 修改数据库选项 +#### 修改数据库选项 `ALTER DATABASE` 语句可以用来修改数据库的选项。 @@ -47,7 +44,24 @@ ALTER DATABASE db SET 'ttl'='1d'; ALTER DATABASE db UNSET 'ttl'; ``` -### 增加列 +## ALTER TABLE + +## 语法 + +```sql +ALTER TABLE [db.]table + [ADD COLUMN name type [options] + | DROP COLUMN name + | MODIFY COLUMN name type + | MODIFY COLUMN name SET FULLTEXT [WITH ] + | RENAME name + | SET = [, ...] + ] +``` + +### 示例 + +#### 增加列 在表中增加新列: @@ -75,7 +89,7 @@ ALTER TABLE monitor ADD COLUMN app STRING DEFAULT 'shop' PRIMARY KEY; ``` -### 移除列 +#### 移除列 从表中移除列: @@ -85,7 +99,7 @@ ALTER TABLE monitor DROP COLUMN load_15; 后续的所有查询立刻不能获取到被移除的列。 -### 修改列类型 +#### 修改列类型 修改列的数据类型 @@ -95,7 +109,7 @@ ALTER TABLE monitor MODIFY COLUMN load_15 STRING; 被修改的的列不能是 tag 列(primary key)或 time index 列,同时该列必须允许空值 `NULL` 存在来保证数据能够安全地进行转换(转换失败时返回 `NULL`)。 -### 修改表的参数 +#### 修改表的参数 `ALTER TABLE` 语句也可以用来更改表的选项。 当前支持修改以下表选项: @@ -130,8 +144,7 @@ ALTER TABLE monitor SET 'compaction.twcs.max_inactive_window_runs'='6'; ALTER TABLE monitor UNSET 'ttl'; ``` - -### 修改列全文索引选项 +#### 修改列全文索引选项 启用列的全文索引: @@ -156,7 +169,7 @@ ALTER TABLE monitor MODIFY COLUMN load_15 UNSET FULLTEXT; 当列的全文索引未开启过时,可以启用全文索引,并设置 `analyzer` 和 `case_sensitive` 选项;当列的全文索引选项已经启用时,可以关闭全文索引,**但不能修改选项**。 -### 重命名表 +#### 重命名表 ```sql ALTER TABLE monitor RENAME monitor_new;