COMMENT

为现有对象添加注释或覆盖现有注释。

可以将注释添加到所有对象(用户、角色、仓库、数据库、表等)。注释也可以添加到各个表列中。

语法

COMMENT [IF EXISTS] ON <object_type> <object_name> IS '<string_literal>';

COMMENT [IF EXISTS] ON COLUMN <table_name>.<column_name> IS '<string_literal>';
Copy

使用说明

  • 除了此命令之外,还可以在创建或更改对象时添加注释:

  • 向表列中添加注释时使用的语法略有不同:

    • 可以在创建时添加注释,方法是在列声明后面加上 COMMENT 关键字(而不是属性)。

    • 然后可以使用此命令更改注释。

  • 关于元数据:

    注意

    客户应确保在使用 Snowflake 服务时,不会将个人数据(用户对象除外)、敏感数据、出口管制数据或其他受监管数据作为元数据输入。有关更多信息,请参阅 Snowflake 中的元数据字段

示例

首先创建一个带有注释的架构,然后覆盖该注释:

CREATE SCHEMA my_schema COMMENT='this is comment1';

SHOW SCHEMAS LIKE '%schema%';

+-------------------------------+--------------------+------------+------------+---------------+--------------+-----------------------------------------------------------+---------+----------------+
| created_on                    | name               | is_default | is_current | database_name | owner        | comment                                                   | options | retention_time |
|-------------------------------+--------------------+------------+------------+---------------+--------------+-----------------------------------------------------------+---------+----------------|
| 2018-06-26 11:06:55.994 -0700 | INFORMATION_SCHEMA | N          | N          | YDB           |              | Views describing the contents of schemas in this database |         | 1              |
| 2018-06-26 11:06:30.532 -0700 | MY_SCHEMA          | N          | Y          | YDB           | SYSADMIN     | this is comment1                                          |         | 1              |
+-------------------------------+--------------------+------------+------------+---------------+--------------+-----------------------------------------------------------+---------+----------------+

COMMENT ON SCHEMA my_schema IS 'now comment2';

SHOW SCHEMAS LIKE '%schema%';

+-------------------------------+--------------------+------------+------------+---------------+--------------+-----------------------------------------------------------+---------+----------------+
| created_on                    | name               | is_default | is_current | database_name | owner        | comment                                                   | options | retention_time |
|-------------------------------+--------------------+------------+------------+---------------+--------------+-----------------------------------------------------------+---------+----------------|
| 2018-06-26 11:06:55.994 -0700 | INFORMATION_SCHEMA | N          | N          | YDB           |              | Views describing the contents of schemas in this database |         | 1              |
| 2018-06-26 11:06:30.532 -0700 | MY_SCHEMA          | N          | Y          | YDB           | SYSADMIN     | now comment2                                              |         | 1              |
+-------------------------------+--------------------+------------+------------+---------------+--------------+-----------------------------------------------------------+---------+----------------+
Copy

创建一个带有表列注释的表,然后覆盖该注释:

CREATE TABLE my_table(my_column string COMMENT 'this is comment3');

DESC TABLE my_table;

+-----------+-------------------+--------+-------+---------+-------------+------------+-------+------------+------------------+
| name      | type              | kind   | null? | default | primary key | unique key | check | expression | comment          |
|-----------+-------------------+--------+-------+---------+-------------+------------+-------+------------+------------------|
| MY_COLUMN | VARCHAR(16777216) | COLUMN | Y     | NULL    | N           | N          | NULL  | NULL       | this is comment3 |
+-----------+-------------------+--------+-------+---------+-------------+------------+-------+------------+------------------+

COMMENT ON COLUMN my_table.my_column IS 'now comment4';

DESC TABLE my_table;

+-----------+-------------------+--------+-------+---------+-------------+------------+-------+------------+--------------+
| name      | type              | kind   | null? | default | primary key | unique key | check | expression | comment      |
|-----------+-------------------+--------+-------+---------+-------------+------------+-------+------------+--------------|
| MY_COLUMN | VARCHAR(16777216) | COLUMN | Y     | NULL    | N           | N          | NULL  | NULL       | now comment4 |
+-----------+-------------------+--------+-------+---------+-------------+------------+-------+------------+--------------+
Copy

创建带有注释的视图,然后覆盖该注释:

CREATE VIEW my_view comment='this is comment5' AS (SELECT * FROM my_table);

SHOW VIEWS LIKE 'my_view';

+-------------------------------+---------+----------+---------------+-------------+----------+------------------+-----------------------------------------------------------------------------+-----------+
| created_on                    | name    | reserved | database_name | schema_name | owner    | comment          | text                                                                        | is_secure |
|-------------------------------+---------+----------+---------------+-------------+----------+------------------+-----------------------------------------------------------------------------+-----------|
| 2018-06-26 11:11:01.048 -0700 | MY_VIEW |          | YDB           | MY_SCHEMA   | SYSADMIN | this is comment5 | CREATE VIEW my_view comment='this is comment5' AS (SELECT * FROM my_table); | false     |
+-------------------------------+---------+----------+---------------+-------------+----------+------------------+-----------------------------------------------------------------------------+-----------+

COMMENT ON VIEW my_view IS 'now comment6';

SHOW VIEWS LIKE 'my_view';

+-------------------------------+---------+----------+---------------+-------------+----------+--------------+-----------------------------------------------------------------------------+-----------+
| created_on                    | name    | reserved | database_name | schema_name | owner    | comment      | text                                                                        | is_secure |
|-------------------------------+---------+----------+---------------+-------------+----------+--------------+-----------------------------------------------------------------------------+-----------|
| 2018-06-26 11:11:01.048 -0700 | MY_VIEW |          | YDB           | MY_SCHEMA   | SYSADMIN | now comment6 | CREATE VIEW my_view comment='this is comment5' AS (SELECT * FROM my_table); | false     |
+-------------------------------+---------+----------+---------------+-------------+----------+--------------+-----------------------------------------------------------------------------+-----------+
Copy
语言: 中文