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 关键字(而不是属性)。

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

  • 若要向约束添加注释,请使用 CREATE TABLECREATE | ALTER TABLE ...CONSTRAINT 命令。

  • DESCRIBE TABLE 输出不显示表约束的注释,例如多列主键。要查看这些注释,请查询 TABLE_CONSTRAINTS 视图

  • 关于元数据:

    注意

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

示例

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

CREATE SCHEMA my_schema COMMENT='this is comment1';

SHOW SCHEMAS LIKE '%schema%';
Copy
+-------------------------------+--------------------+------------+------------+---------------+--------------+-----------------------------------------------------------+---------+----------------+
| 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%';
Copy
+-------------------------------+--------------------+------------+------------+---------------+--------------+-----------------------------------------------------------+---------+----------------+
| 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              |
+-------------------------------+--------------------+------------+------------+---------------+--------------+-----------------------------------------------------------+---------+----------------+

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

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

DESC TABLE my_table;
Copy
+-----------+-------------------+--------+-------+---------+-------------+------------+-------+------------+------------------+
| 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;
Copy
+-----------+-------------------+--------+-------+---------+-------------+------------+-------+------------+--------------+
| 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 |
+-----------+-------------------+--------+-------+---------+-------------+------------+-------+------------+--------------+

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

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

SHOW VIEWS LIKE 'my_view';
Copy
+-------------------------------+---------+----------+---------------+-------------+----------+------------------+-----------------------------------------------------------------------------+-----------+
| 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     |
+-------------------------------+---------+----------+---------------+-------------+----------+--------------+-----------------------------------------------------------------------------+-----------+
语言: 中文