# Comment

Adds a comment or removes an existing comment for an existing table or column object.

## COMMENT

```sql
COMMENT ON (TABLE | COLUMN) <object_name> IS (<string_literal> | NULL);
```

Create or remove a comment for a `TABLE` or `COLUMN` object of name `object_name`. The comment must be a string literal or `NULL`. If `NULL`, the comment is removed.\
\
Only super-users or owners of the object can modify comments on the object.

Column and table comments can be viewed either in the `information_schema` system tables, or in the result of the `SHOW CREATE TABLE` command run on the relevant table.

{% hint style="info" %}
Currently comments are not supported with the `CREATE TABLE` command, and `COMMENT ON` is the canonical means to set or unset comments.
{% endhint %}

### **Examples**

1. Create a table and add a comments to it.

{% code overflow="wrap" %}

```sql
CREATE TABLE employees (id INT, salary BIGINT);
-- Add a comment to the 'employees' table
COMMENT ON TABLE employees IS 'This table stores employee information';
-- Add a comment to the 'salary' column
COMMENT ON COLUMN employees.salary IS 'Stores the salary of the employee';
```

{% endcode %}

{% hint style="info" %}
When specifying the name of the `COLUMN` object, it must be of the form `<TABLE>.COLUMN>` to uniquely identify it.
{% endhint %}

2. Show the comments and the DDL of the table.

{% code overflow="wrap" %}

```sql
SHOW CREATE TABLE employees;

CREATE TABLE employees /* This table stores employee information */ (
  id INTEGER,
  salary BIGINT /* Stores the salary of the employee */);
1 rows returned.
```

{% endcode %}

{% hint style="info" %}
Currently `COMMENT ON` is supported only on tables and and columns of that table. Other objects such as `VIEW` are not currently supported.
{% endhint %}

3. View the table and column comment in respective system table.

{% code overflow="wrap" %}

```sql
-- Connect to information_schema database
\c information_schema admin XXXXXXXX

-- Select subset of columns from the tables system table
SELECT table_id,table_name,"comment" FROM tables where table_name = 'employees';

-- Returns one result for the table comment
table_id|table_name|comment
5|employees|This table stores employee information
1 rows returned.

-- Select subset of columns from the columns system table
SELECT table_id,table_name,column_id,column_name,"comment" FROM columns where table_name = 'employees';

-- Returns two results, one of the columns has no comment.
table_id|table_name|column_id|column_name|comment
5|employees|1|id|NULL
5|employees|2|salary|Stores the salary of the employee
2 rows returned.
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.heavy.ai/sql/data-definition-ddl/comment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
