Skip to main content
The COMMENT ON statement associates comments to databases, tables, columns, indexes, or types. The COMMENT ON statement performs a schema change. For more information about how online schema changes work in CockroachDB, see Online Schema Changes.

Required privileges

The user must have the CREATE privilege on the object they are commenting on.

Synopsis

comment syntax diagram

Parameters

Examples

Setup

To follow along, run cockroach demo to start a temporary, in-memory cluster with the movr sample dataset preloaded:

Add a comment to a database

To add a comment to a database:
To view database comments, use SHOW DATABASES:

Add a comment to a table

To add a comment to a table:
To view table comments, use SHOW TABLES:
You can also view comments on a table with SHOW CREATE:

Add a comment to a column

To add a comment to a column:
To view column comments, use SHOW COLUMNS:

Add a comment to an index

Suppose we create an index on the name column of the users table:
To add a comment to the index:
To view column comments, use SHOW INDEXES... WITH COMMENT:

Add a comment to a type

Issue a SQL statement to create a type:
To view the type you just created, use SHOW TYPES:
To add a comment on the type, use a statement like the following:
To view all comments on types, make a selection query against the system.comments table:

Remove a comment from a database

To remove a comment from a database:

Remove a comment from a type

To remove the comment from the type you created in the preceding example, add a NULL comment:

Known limitations

  • The COMMENT ON statement associates comments to databases, tables, or columns. However, the internal table ( system.comments ) in which these comments are stored is not captured by a BACKUP of an individual table or database. As a workaround, take a cluster backup instead, as the system.comments table is included in cluster backups.

See also