How to Add / Remove comments to a table or column using the COMMENT ON statement.

In Oracle, you can add comments to a table or column using the COMMENT ON statement.

1. Adding a Comment to a Table

COMMENT ON TABLE table_name IS 'Your table description';

Example:

COMMENT ON TABLE employees IS 'Stores employee details including personal and job-related information';

2. Adding a Comment to a Column

COMMENT ON COLUMN table_name.column_name IS 'Your column description';

Example:

COMMENT ON COLUMN employees.salary IS 'Salary of the employee in USD';

3. Viewing Comments

To check table and column comments, query the data dictionary views:

  • For table comments:

    SELECT table_name, comments
    FROM user_tab_comments WHERE table_name = 'EMPLOYEES';
  • For column comments:

    SELECT column_name, comments
    FROM user_col_comments WHERE table_name = 'EMPLOYEES';

4. Removing Comments

To remove a comment, set it to NULL:

COMMENT ON TABLE employees IS NULL;
COMMENT ON COLUMN employees.salary IS NULL;

Post a Comment

And that's all there is to it!

If anyone has any other questions or requests for future How To posts, you can either ask them in the comments or email me. Please don't feel shy at all!

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

Previous Post Next Post