COMMENT

Adds a comment or overwrites an existing comment for an existing object.

Comments can be added to all objects (users, roles, warehouses, databases, tables, etc.). You can use this command to add comments to individual table columns, but not to constraints on columns.

Syntax

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

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

Usage notes

  • You can also add comments when you are creating or altering objects:

  • A slightly different syntax is used for adding comments to table columns:

    • A comment can be added at creation by following the column declaration with the COMMENT keyword (not property).

    • The comment can then be changed using this command.

  • To add a comment to a constraint, use the CREATE TABLE or CREATE | ALTER TABLE … CONSTRAINT commands.

  • The DESCRIBE TABLE output does not show comments for table constraints, such as multi-column primary keys. To see these comments, query the TABLE_CONSTRAINTS view.

  • Regarding metadata:

    Attention

    Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.

Examples

Initially create a schema with a comment, then overwrite the comment:

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 a table with a comment on a table column, then overwrite the comment:

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 a view with a comment, then overwrite the comment:

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     |
+-------------------------------+---------+----------+---------------+-------------+----------+--------------+-----------------------------------------------------------------------------+-----------+