COMMENT¶
既存のオブジェクトのコメントを追加するか、既存のコメントを上書きします。
コメントはすべてのオブジェクト(ユーザー、ロール、ウェアハウス、データベース、テーブルなど)に追加できます。このコマンドを使用すると、個々のテーブル列にコメントを追加できますが、列の制約には追加できません。
構文¶
COMMENT [IF EXISTS] ON <object_type> <object_name> IS '<string_literal>';
COMMENT [IF EXISTS] ON COLUMN <table_name>.<column_name> IS '<string_literal>';
使用上の注意¶
また、オブジェクトの作成や変更時にコメントを追加することもできます:
CREATE <オブジェクト> または ALTER <オブジェクト> コマンドで
COMMENT
パラメーターを指定します。COMMENT
パラメーターを ALTER <オブジェクト> コマンドで使用して、既存のコメントをいつでも変更することもできます。
テーブル列にコメントを追加するために、わずかに異なる構文が使用されます。
作成時にコメントを追加するには、列宣言の後に
COMMENT
キーワード(プロパティではない)を追加します。このコマンドを使用して、コメントを変更できます。
制約にコメントを追加するには、 CREATE TABLE または CREATE | ALTER TABLE ... CONSTRAINT コマンドを使用します。
DESCRIBE TABLE 出力には、複数列の主キーのようなテーブル制約のコメントは表示されません。これらのコメントを見るには、 TABLE_CONSTRAINTS ビュー をクエリします。
メタデータについて。
注意
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 |
+-------------------------------+--------------------+------------+------------+---------------+--------------+-----------------------------------------------------------+---------+----------------+
テーブルの列にコメントを付けてテーブルを作成し、コメントを上書きします。
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 |
+-----------+-------------------+--------+-------+---------+-------------+------------+-------+------------+--------------+
コメント付きのビューを作成してから、コメントを上書きします。
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 |
+-------------------------------+---------+----------+---------------+-------------+----------+--------------+-----------------------------------------------------------------------------+-----------+