Skip to content
ClickHouse Docs
ClickHouse DocsClickHouse Docs

ALTER TABLE ... MODIFY COMMENT

添加、修改或删除表注释,无论之前是否已设置注释。

注释的更改会同时反映在 system.tablesSHOW CREATE TABLE 查询中。

语法

ALTER TABLE [db].name [ON CLUSTER cluster] MODIFY COMMENT 'Comment'

示例

要创建带注释的表:

Querysql
CREATE TABLE table_with_comment
(
    `k` UInt64,
    `s` String
)
ENGINE = Memory()
COMMENT 'The temporary table';

如需修改表注释:

Querysql
ALTER TABLE table_with_comment
MODIFY COMMENT 'new comment on a table';

要查看修改后的注释:

Querysql
SELECT comment
FROM system.tables
WHERE database = currentDatabase() AND name = 'table_with_comment';
Responsetext
┌─comment────────────────┐
│ new comment on a table │
└────────────────────────┘

要删除表注释:

Querysql
ALTER TABLE table_with_comment MODIFY COMMENT '';

要验证该注释已被移除:

Querysql
SELECT comment
FROM system.tables
WHERE database = currentDatabase() AND name = 'table_with_comment';
Responsetext
┌─comment─┐
│         │
└─────────┘

注意事项

对于复制表,不同副本上的注释可以不同。 修改注释仅会应用到单个副本。

该功能自 23.9 版本起可用。在更早的 ClickHouse 版本中无法使用。

Navigation