Skip to content

Commit

Permalink
docs: refine
Browse files Browse the repository at this point in the history
  • Loading branch information
CookiePieWw committed Nov 21, 2024
1 parent c1882a4 commit e0b58b0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 36 deletions.
52 changes: 31 additions & 21 deletions docs/reference/sql/alter.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,22 @@
* Rename a table
* Modify table options

## Syntax
## ALTER DATABASE

### Syntax

```sql
ALTER DATABASE db
[SET <option_name>=<option_value> [, ...]
| UNSET <option_name> [, ...]
]

ALTER TABLE [db.]table
[ADD COLUMN name type [options]
| DROP COLUMN name
| MODIFY COLUMN name type
| MODIFY COLUMN name SET FULLTEXT [WITH <options>]
| MODIFY COLUMN name UNSET FULLTEXT
| RENAME name
| SET <option_name>=<option_value> [, ...]
| UNSET <option_name>[, ...]
]
```

## 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.
Expand All @@ -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 <options>]
| MODIFY COLUMN name UNSET FULLTEXT
| RENAME name
| SET <option_name>=<option_value> [, ...]
| UNSET <option_name>[, ...]
]
```

### Examples

#### Add column

Adds a new column to the table:

Expand All @@ -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:

Expand All @@ -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

Expand All @@ -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.

Expand Down Expand Up @@ -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:

Expand All @@ -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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
* 重命名表
* 修改表选项

## Syntax
## ALTER DATABASE

```sql
ALTER DATABASE db
[SET <option_name>=<option_value> [, ...]
| UNSET <option_name> [, ...]
]
### 语法

```sql
ALTER TABLE [db.]table
[ADD COLUMN name type [options]
| DROP COLUMN name
Expand All @@ -26,9 +23,9 @@ ALTER TABLE [db.]table
]
```

## 示例
### 示例

### 修改数据库选项
#### 修改数据库选项

`ALTER DATABASE` 语句可以用来修改数据库的选项。

Expand All @@ -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 <options>]
| RENAME name
| SET <option_name>=<option_value> [, ...]
]
```

### 示例

#### 增加列

在表中增加新列:

Expand Down Expand Up @@ -75,7 +89,7 @@ ALTER TABLE monitor ADD COLUMN app STRING DEFAULT 'shop' PRIMARY KEY;
```


### 移除列
#### 移除列

从表中移除列:

Expand All @@ -85,7 +99,7 @@ ALTER TABLE monitor DROP COLUMN load_15;

后续的所有查询立刻不能获取到被移除的列。

### 修改列类型
#### 修改列类型

修改列的数据类型

Expand All @@ -95,7 +109,7 @@ ALTER TABLE monitor MODIFY COLUMN load_15 STRING;

被修改的的列不能是 tag 列(primary key)或 time index 列,同时该列必须允许空值 `NULL` 存在来保证数据能够安全地进行转换(转换失败时返回 `NULL`)。

### 修改表的参数
#### 修改表的参数

`ALTER TABLE` 语句也可以用来更改表的选项。
当前支持修改以下表选项:
Expand Down Expand Up @@ -130,8 +144,7 @@ ALTER TABLE monitor SET 'compaction.twcs.max_inactive_window_runs'='6';
ALTER TABLE monitor UNSET 'ttl';
```


### 修改列全文索引选项
#### 修改列全文索引选项

启用列的全文索引:

Expand All @@ -156,7 +169,7 @@ ALTER TABLE monitor MODIFY COLUMN load_15 UNSET FULLTEXT;

当列的全文索引未开启过时,可以启用全文索引,并设置 `analyzer``case_sensitive` 选项;当列的全文索引选项已经启用时,可以关闭全文索引,**但不能修改选项**

### 重命名表
#### 重命名表

```sql
ALTER TABLE monitor RENAME monitor_new;
Expand Down

0 comments on commit e0b58b0

Please sign in to comment.