COMMENT ON

Use the COMMENT ON command to specify or replace a comment for an object.

Use the COMMENT ON command to:
  • Specify a comment for a database object.
  • Replace an existing comment.
  • Delete a comment by specifying a null string.
To retrieve a comment, issue the \dd CLI command.

Each object can have at most one comment. When you drop an object, the system automatically drops the corresponding comment.

Any user who is connected to a database can view all comments for objects in the database, so do not put security-critical or confidential information into comments.

Syntax

Syntax to add a comment:
COMMENT ON [ <object_type> <object_name> | 
  COLUMN <table>.<col> ] IS '<text>'

Inputs

The COMMENT ON command takes the following inputs:
Table 1. COMMENT ON inputs
Input Description
<object_type> The type of object:
  • DATABASE
  • SEQUENCE
  • SYNONYM
  • TABLE
  • VIEW
  • FUNCTION
  • AGGREGATE
  • PROCEDURE
  • LIBRARY
<object_name> The name of the object.
<table> The name of the table.
<col> The name of the column.
<text> The comment text.

Output

The COMMENT command has the following output:

Table 2. COMMENT output
Output Description
Comment The comment was successfully added or replaced.

Privileges

You can specify comments for any objects that you own. For other objects, you must be the admin user, the owner of the database or schema where the object is defined, or your account must have the Alter privilege for theobject or for that class of objects.

Usage

The following provides sample usage.
  • Add a comment to the table mytable:
    MYDB.SCH1(USER)=> COMMENT ON my_table IS 'This is my table.';
    
  • Add comments to a database, sequence, view, and column:
    MYDB.SCH1(USER)=> COMMENT ON DATABASE my_database IS 'Development 
    Database';
    MYDB.SCH1(USER)=> COMMENT ON SEQUENCE my_sequence IS 'Used to 
    generate primary keys';
    MYDB.SCH1(USER)=> COMMENT ON VIEW my_view IS 'View of departmental 
    costs';
    MYDB.SCH1(USER)=> COMMENT ON COLUMN my_table.my_field IS 'Employee ID 
    number';