In oracle, the comment on command is used to describe tables or fields. The syntax is as follows:
Copy codeThe Code is as follows:
COMMENT ON
{TABLE [schema.]
{Table | view}
| COLUMN [schema.]
{Table. | view. | materialized_view.} column
| OPERATOR [schema.] operator
| INDEXTYPE [schema.] indextype
| Materialized view materialized_view
}
IS 'text ';
The usage is as follows:
1. Description of the table
Copy codeThe Code is as follows:
Comment on table table_name is 'comments _ on_tab_information ';
2. Description of the columns in the table
Copy codeThe Code is as follows:
Comment on column table. column_name is 'comments _ on_col_information ';
3. View table description
Copy codeThe Code is as follows:
SQL> select * from user_tab_comments where TABLE_NAME = 'ployees ';
Copy codeThe Code is as follows:
TABLE_NAME TABLE_TYPE COMMENTS
---------------------------------------------------
Employees table employee TABLE
SQL> select * from user_tab_comments where comments is not null;
TABLE_NAME TABLE_TYPE COMMENTS
-------------------------------------------------------------------
Employees table employee TABLE
4. view the description of the columns in the table.
Copy codeThe Code is as follows:
SQL> select * from user_col_comments where TABLE_NAME = 'ployees ';
Copy codeThe Code is as follows:
TABLE_NAME COLUMN_NAME COMMENTS
------------------------------------------------------------------------
EMPLOYEES EMPLOYEE_ID
EMPLOYEES MANAGER_ID
EMPLOYEES FIRST_NAME
EMPLOYEES LAST_NAME
EMPLOYEES TITLE
SALARY of SALARY EMPLOYEES
SQL> select * from user_col_comments where comments is not null;
TABLE_NAME COLUMN_NAME COMMENTS
-------------------------------------------------------------------------
SALARY of SALARY EMPLOYEES
5. You can also view the table-level and column-level descriptions from the following views:
Copy codeThe Code is as follows:
ALL_COL_COMMENTS
USER_COL_COMMENTS
ALL_TAB_COMMENTS
USER_TAB_COMMENTS
6. Delete table-level description, that is, leave it blank
Copy codeThe Code is as follows:
SQL> comment on table employees is '';
Comment added
SQL> select * from user_tab_comments where TABLE_NAME = 'ployees ';
TABLE_NAME TABLE_TYPE COMMENTS
------------------------------------------------------
EMPLOYEES TABLE
7. Delete the column-level description and leave it empty.
Copy codeThe Code is as follows:
SQL> comment on column employees. salary is '';
Comment added
SQL> select * from user_col_comments where TABLE_NAME = 'ployees ';
TABLE_NAME COLUMN_NAME COMMENTS
-------------------------------------------------------------------------
EMPLOYEES EMPLOYEE_ID
EMPLOYEES MANAGER_ID
EMPLOYEES FIRST_NAME
EMPLOYEES LAST_NAME
EMPLOYEES TITLE
EMPLOYEES SALARY