Was this helpful?
Comments to Describe Tables and Views
When working with tables and views in applications, it is helpful to include commentary about the structure and uses of tables and views.
Tables and views can be commented with:
Comment lines in SQL or a host language, for example, “/*comment*/” or “--comment”
Comments specified with the COMMENT ON statement
Comments in embedded SQL (ESQL) programs specified with the DECLARE TABLE statement
When using Director or VDBA, tables and views are self-documenting. For example, you can see the definition of a view at a glance, as well as its rows and the grants that have been defined. For a table, you can view its rows and columns, as well as properties, statistics, and other pertinent information.
The Comment On Statement
The COMMENT ON statement allows you to add commentary to SQL programs. Using this statement, you can create a comment for the table as a whole and for individual columns in the table.
For example, to add a remark on the name column and on the status column of the employee table:
COMMENT ON COLUMN employee.name IS
  'name in the format: lastname, firstname';

COMMENT ON COLUMN employee.status IS
  'valid codes are:
     01, exempt; 02, non-exempt; 03, temp';
To delete a comment, specify an empty string. For example, the comment on the status column can be deleted by the statement:
COMMENT ON COLUMN employee.status IS '';
For complete details, see the comment on statement in the SQL Reference Guide.
The Declare Table Statement
The DECLARE TABLE statement can be used to describe the structure of a table in ESQL programs. With this statement, you can document the columns and data types associated with a table.
For example, the employee table can be described with a DECLARE TABLE statement as follows:
exec sql declare userjoe.employee table
         (
         emp_number    integer2 not null not default,
         last_name     varchar(20) not null,
         first_name    varchar(20),
         birth_date    date not null not default
         );
For complete details, see the entry for the DECLARE TABLE statement in the SQL Reference Guide. For information on ESQL programs, see the chapter “Embedded SQL” in the SQL Reference Guide.
 
Last modified date: 01/30/2023